-
Notifications
You must be signed in to change notification settings - Fork 4
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
Reduce allocations #115
Reduce allocations #115
Conversation
Would having opcache enabled close the performance gap between the implementations, thus rendering the extension moot? IIRC we would need to run this with PHP-FPM to test this out. (It's been like 5 years since I last developed with PHP, so I might be wrong.) |
Hmm, no, I get pretty much the same numbers on The
That's a good point. I ran the benchmarks again with |
Interesting, did you try with both PHP 7.4 and 8? |
4e4b2e7
to
dbce73b
Compare
This commit aims to reduce the number of times emalloc() is called. Instead of allocating arrays and strings each time every time a literal or node list is compared in the interpreter, create literals and node list once at parse time. In addition, use a stack-allocated memory pool for AST nodes. This has the benefit of eliminating calls to emalloc(), allocating contiguous blocks of memory, and reducing the risk of future memory leaks. The tradeoff we're making here is that there is a fixed number of AST nodes (64), so there's a limit imposed on the size of the JSONPath query. We'll see in the future if this poses a problem, in which case we can implement Viktor's dynamic memory pool solution. (6cf186b)
dbce73b
to
7a313cd
Compare
@crocodele I reverted the buggy dynamic memory pool. See commit message in 7a313cd for a summary of the changes. |
This change reduces the size of the stack-allocated memory pool to < 2Kib and removes the limit imposed on the number of elements in the index filter. With a bit of more work, we could support integer array operands. (See tests/022.phpt)
ad4c2a8
to
fd756e7
Compare
@crocodele In this branch AST nodes are retrieved from a stack-allocated array instead of dynamic allocation. When I run the benchmarks on the branch, the
JsonPathPhpExtensionBenchmark
beatsNativePhpBenchmark
onbenchMediumDataset
. Do you get the same results?