-
Notifications
You must be signed in to change notification settings - Fork 0
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
Select correct sizes and types for stack/tree ArrayBuffers #139
Comments
I think it's very unlikely to have a visited array which need to hold the entire input stream of characters. In theory this is a valid option, but in practice this is more than unlikely.
I cannot imagine a stack with more than 64k items on it. That sound very huge.
This could indeed be true. The tree should be able to grow really huge. A Uint32Array would be a good solution here I think.
We should add a clone operation to the top level. |
We have several typed arrays in our code whose size depends on the input.
visited
In our generated lexer is an array
visited
which always has the size1024
but it should potentially be able to contain the entire input string.par-gen/parsers/json/generated/lexer-initial.js
Lines 1359 to 1381 in fe610c3
I see several options here:
next
function which would be much more expensiveparse
function and pass it to the next function (would be less expensive, but still has overhead)Math.pow(2, 32) - 1
according to MDN) because it allocates only virtual memory until we fill itstack
At the moment we generate either an
Uint8Array
orUint16Array
dependending on the number of states that we have.The stack can grow larger than the number of states we have, for example deeply nested arrays / objects would stay on the stack until their matching closing braces are found. Additionally, since we store two stacks in that array, we have double the size.
par-gen/parsers/json/generated/parser.js
Line 3272 in fe610c3
I see several options here:
input bytes * 2
would suffice), but then we have allocations inside ourparse
functionMath.pow(2, 32) - 1
Uint32Array
, because aUint16Array
can only contain up to65535
(which means we could have a maximum of 32k stack items)tree
The
tree
array has the same problem as thestack
array above: It can get very large for long input strings, even larger than thestack
, since we treat it as append only.par-gen/parsers/json/generated/parser.js
Line 3288 in fe610c3
I see several ideas for improvements here:
Math.pow(2, 32) - 1
Uint32Array
, because aUint16Array
can only contain up to65535
(which means we could have a maximum of 64k nodes)done
state, so that the nextparse
doesn't overwrite a previousparse
(for example:const result1 = parse('...'); const result 2 = parse('...');
would overwrite result1)parse()
function, but I suppose that will get problematic for long running processes (such as a watcher task) since we never free the memory of unused treesThe text was updated successfully, but these errors were encountered: