Skip to content
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

added fix for utf8 multi-byte boundary when it is split between chunks, ... #12

Merged
merged 2 commits into from Jun 18, 2013

Conversation

jlank
Copy link

@jlank jlank commented Jun 12, 2013

...also created a test for this scenario, and made sure all current tests still pass in node and on the browser side. Sorry for the kinda messy diff, a force of habit of mine is removing trailing whitespace in vim with ,ss, it's so fun to get rid of them! :P

…s, also created a test for this scenario, and made sure all current tests still pass in node and on the browser side
@jlank
Copy link
Author

jlank commented Jun 12, 2013

In reference to #11

dscape added a commit that referenced this pull request Jun 18, 2013
added fix for utf8 multi-byte boundary when it is split between chunks, ...
@dscape dscape merged commit 4828c01 into dscape:master Jun 18, 2013
@dscape
Copy link
Owner

dscape commented Jun 18, 2013

@jlank are you using clarinet in production? would be great to have that switch replaced with if then elses, cause I know it's a problem for V8

cc @mraleph @felixge

@dscape
Copy link
Owner

dscape commented Jun 18, 2013

Publishing this right now. Reference to the other case:

creationix/jsonparse#9

@felixge
Copy link

felixge commented Jun 18, 2013

? would be great to have that switch replaced with if then elses, cause I know it's a problem for V8

I don't think it causes any problems, but it essentially performs the same as if / else would. That is: it goes through each case and evaluates it one after the other, rather than using some form of optimized lookup table to jump into the right case directly. My workaround this has always been to reduce the number of cases / times I have to hit the switch statement itself, which is usually accomplished by buffering more data and keeping more state of the state machine in my function scope. (Also: my understanding of this is probably very limited, so don't apply this advise unless @mraleph confirms this / you can verify it in a benchmark independently)

Related: Seems like @indutny tried to improve this before: https://codereview.chromium.org/8499010/

@mraleph
Copy link

mraleph commented Jun 18, 2013

If switch cases are integers it would not behave any different from a sequence of ifs.

If switch cases are string literals then in some cases it might behave worse: https://code.google.com/p/v8/issues/detail?id=2684

If switch fits neither of those two cases the function it is contained in is never optimized.

Manually reordering switch to have most common cases on top will improve performance. At least until V8 starts doing some sophisticated switch optimizations itself.

@jlank
Copy link
Author

jlank commented Jun 18, 2013

@dscape I'm not using it in production, I identified the bug initially using @dominictarr's JSONStream which depends on jsonparse and noticed this same issue was present for clarinet. Also I'm unclear on which switch statement you are referring to (I don't think my PR added one), I'd be happy to convert it if you could give me a line number though.

@ariya
Copy link

ariya commented Jun 18, 2013

Echoing what @mraleph said above.

My own experience on the use of switch case: http://ariya.ofilabs.com/2012/04/javascript-switch-case-deoptimization.html. If you can run V8 and check your code, that gives a better insight than any amount of guessing :)

Profile-guided tweaks is also easy: http://ariya.ofilabs.com/2012/02/javascript-branching-and-code-shuffling.html.

Just my $0.02.

@indutny
Copy link

indutny commented Jun 18, 2013

You might like this then: https://codereview.chromium.org/16128004/

@jlank
Copy link
Author

jlank commented Jun 18, 2013

@ariya thanks for the insightful blog posts, they give good context. I (think I) understand what @dscape was getting at now. I can go ahead and try an implementation with switch case's and see what benchmarks better in V8 instead of speculating.

@dscape
Copy link
Owner

dscape commented Jun 18, 2013

@jlank that would be awesome!

@ariya
Copy link

ariya commented Jun 18, 2013

@indutny Yep, looking forward to trying it out :)

@indutny
Copy link

indutny commented Jun 18, 2013

@ariya It hasn't landed, but you can try pulling it in and running benchmarks to see if it helps.

@dscape
Copy link
Owner

dscape commented Jun 19, 2013

Thank everyone for the input!! :) This is why open source is awesome.

@jlank would love to read a blog post about your findings in the end, sounds like you'll have a lot of insight into this by then 💯

@jlank
Copy link
Author

jlank commented Jun 19, 2013

@dscape you can count on it.. I have a draft post from my initial fix to jsonparse that is sitting in the publish queue. I'll use the benchmarking for clarinet to round out the post. stay tuned...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants