-
Notifications
You must be signed in to change notification settings - Fork 121
Use batch APIs to create arrays and hashes #370
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
Conversation
b13d5c4
to
2ffc3c9
Compare
Basically a port of ruby/json#678 Rather than to allocate the container and push elements one by one, we accumulate them on a stack and then use the faster batch APIs to directly create the final container. The original action stack remains, as we need to keep track of what we're currently parsing and how big it is. But for the recursive cases, we no longer need to create a child stack.
2ffc3c9
to
ec22a5d
Compare
Using ruby/json benchmarks. Before
After:
So it helps a bit, but really not as much. The reason is likely because batch APIs aren't that much faster if you already allocate the containers with the right size like we were doing, wheras with The one optimization we really ought to port though, is the hash key cache, as profiling shows that's where we spent the most time by far. |
Extracted from: #370 As initially implemented, we allocate a new stack whenever we encounter a child stack. This means acquiring a whole 4kiB chunk from the arena, which generally is overkill. Instead we can introduce a new type of stack item, that behave just like a Hash or Array.
Closing in favor of #370. I don't think the batch API are worth it here, but it's worth no longer allocating a child stack. |
Basically a port of ruby/json#678
Rather than to allocate the container and push elements one by one, we accumulate them on a stack and then use the faster batch APIs to directly create the final container.
The original action stack remains, as we need to keep track of what we're currently parsing and how big it is.
But for the recursive cases, we no longer need to create a child stack.