Uh oh!
There was an error while loading. Please reload this page.
url: improve parsing speed and code style - #419
Conversation
mscdex
commented
Jan 14, 2015
There's still a |
bnoordhuis
commented
Jan 14, 2015
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. |
ysmood
commented
Jan 15, 2015
@bnoordhuishttp://jsperf.com/regex-inside-vs-outside |
sonewman
commented
Jan 15, 2015
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 |
ysmood
commented
Jan 15, 2015
@mscdex The missed one is fixed: 54c2a9f17873f69dc1906909e3013b0ec0ae24ba |
sonewman
commented
Jan 15, 2015
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. |
sonewman
commented
Jan 15, 2015
Bare in mind, i am playing devil's advocate here 😉 |
ysmood
commented
Jan 15, 2015
@sonewman For a running server that may run months, the startup speed trade off is not that important, but this |
sonewman
commented
Jan 15, 2015
yes this is very true, I have similar considerations myself as it may also need to be called when using |
ysmood
commented
Jan 15, 2015
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. |
sonewman
commented
Jan 15, 2015
It's also interesting that Safari is WAY faster! |
sonewman
commented
Jan 15, 2015
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. |
mscdex
commented
Jan 15, 2015
Additionally moving the url formatting code into a separate function which accepts an object (avoiding With node v0.10.33 + url.js from iojs: |
sonewman
commented
Jan 15, 2015
@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. |
mscdex
commented
Jan 15, 2015
It also looks like avoiding the use of the And just for kicks, removing the |
sonewman
commented
Jan 15, 2015
I often wondered about those methods... it's likely they can't be inlined as they are in a separate file. |
mscdex
commented
Jan 15, 2015
I just tested my |
sonewman
commented
Jan 15, 2015
yeah that is pretty insane |
rvagg
commented
Jan 27, 2015
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.
Fishrock123
commented
Jan 27, 2015
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) |
bnoordhuis
commented
Jan 27, 2015
@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. |
ysmood
commented
Jan 27, 2015
At least this PR make the code style more unified, and apparently has no side effect, so why not merge it? |
Fishrock123
commented
Feb 10, 2015
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.