-
Notifications
You must be signed in to change notification settings - Fork 47.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize escaping of IDs #11756
Optimize escaping of IDs #11756
Conversation
…g up a significant amount of time in benchmarks.
Thanks! I’ll take a look later. Does #11749 solve your benchmarking problems? |
I updated from master today, so I don't think so, but I'll double check. |
…hought the previous version would have worked.
Two things:
|
It seems you're maybe not merging this, but would it not make sense to instead just do a pre-check and if there's a match then invoke the function as-is, otherwise return the passed string. The expansion of the replace code is quite a lot more complex and difficult to read, and I doubt it has any meaningful impact (whereas having the pre-check does have an impact). I'm even surprised it would be faster than just letting the native replace-code do its thing, this is certainly a performance flaw in the browser JS engine and there's every reason to believe the native function will be faster in the future. |
Great idea, and I'd be happy to do that!
It's been this way for a while, at least since #6862, which was about 18 months ago. I also think there's a chance that it won't get better soon, as regex logic is probably already written in C and has to handle an enormous number of possible cases, which can make optimizations like this hard and/or low priority. But that's totally a guess! |
@aickin What's your latest thinking on this? Is it worth pursuing? |
Eh, I don't really know. It definitely helps my synthetic benchmark, but I've grown less and less confident that that's important; it's really synthetic. I think we should probably close this until there's a better, more real-world SSR test suite available. |
FWIW this would be really great to have for testing other things too. Maybe it's worth focusing some effort on creating one? cc @rauchg Would somebody from Next be interested in helping? |
I did some preliminary profiling of React 16 SSR, and I found something very similar to what I found in #6862, that escaping IDs was taking an inordinate amount of time. I wrote a similar solution that shortcuts for strings that don't have characters to escape and loops over matches. With this new implementation, I was able to make my (admittedly rather synthetic) SSR benchmark run about 20% faster.
I tried to run the react benchmark in
scripts/bench
to see if it agrees with my benchmark, but it gives me errors that thechrome-launcher
module doesn't exist. I think this is because lighthouse's code has been reorganized, and fixing the benchmark seemed a little out of scope for this PR. If anyone knows how to get the benchmark running, I'd appreciate the info!