Why not take Strings as input? #3

thejh opened this Issue Oct 5, 2011 · 0 comments


None yet
1 participant

thejh commented Oct 5, 2011

I saw that @dominictarr wrote about this being much slower than v8s JSON.parse(), put I thought that some improvements would maybe be possible. Some thoughts:
Why don't you take strings as input? I think that this should give you a huge speed improvement because you don't have to call multiple methods per character, but can instead skip over strings until you hit a backslash or quote and then do str.slice(). See this pull request for isaacs sax xml parser which got a 169% speed increase just by adding some fast string-skipping code: isaacs/sax-js#25

If you want to continue accepting buffers, you could just inspect the last six bytes in order to determine where the last complete character ends - a character starts with 0 or 11, so seek back (max 6 bytes) until you hit such a character, then check whether it's a complete character by inspecting the first byte of the character.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment