-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
url: improve parsing speed and code style #419
Conversation
There's still a |
I have a hard time believing that actually makes things faster because V8 normally inlines regular expressions at the call site. Can you run the benchmarks and post numbers? The relevant ones are in benchmark/url. There aren't that many currently, maybe you can add a few while you're there. |
@bnoordhuis http://jsperf.com/regex-inside-vs-outside |
actually this is probably more realistic: http://jsperf.com/regex-inside-vs-outside/2 So it is faster, but not significantly, i mean if you compare it to the spliceOne trick or |
@mscdex The missed one is fixed: 54c2a9f17873f69dc1906909e3013b0ec0ae24ba |
The other thing is, that by defining them up front, it means that all programs have these regexp compiled when they might not even require them. I mean if you are programming a robot, you might not need to parse many URL's in the process. |
Bare in mind, i am playing devil's advocate here 😉 |
@sonewman For a running server that may run months, the startup speed trade off is not that important, but this |
yes this is very true, I have similar considerations myself as it may also need to be called when using |
Beside, this definition convention of regex is used in many other files in io.js. I'm just trying to keep the code style more uniform. |
It's also interesting that Safari is WAY faster! |
Well it is definitely quicker and i'm not going to deny that I the same upfront definitions of regexps in my own code. But there is no harm in the challenge, it just enforces that we are doing things for the right reason and not for the sake of it. I guess I was just alluding that there are probably bigger 🐠 to fry. |
Additionally moving the url formatting code into a separate function which accepts an object (avoiding With node v0.10.33 + url.js from iojs:
|
@mscdex That would definitely be worth doing, thats over 100,000 ops/sec more, in comparison to the 14,000 with just the previous code change. |
It also looks like avoiding the use of the
And just for kicks, removing the
|
I often wondered about those methods... it's likely they can't be inlined as they are in a separate file. |
I just tested my
|
yeah that is pretty insane |
this hasn't got any traction amongst collaborators yet so unless someone steps up and wants to sponsor this change by taking responsibility for it I'm inclined to close it. |
Now all reg patterns are cached outside functions.
This patch appears marginally faster than the current https://gist.github.com/Fishrock123/e9e8664ccc0ba3e1a323 cc @bnoordhuis? (looks like mscdex's format is a lot faster than ours, but that is for another PR) |
@Fishrock123 Are the results repeatable? The url benchmarks unfortunately (but intrinsically) generate a lot of garbage. One run may produce significantly better numbers than the next one, depending on factors like memory pressure, number of running processes, etc. |
At least this PR make the code style more unified, and apparently has no side effect, so why not merge it? |
Seems like a style change. If our policy is otherwise, it can be reopened. |
All the reg patterns should be defined outside the functions. Minor changes were made.