Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I noticed that there was a new utility function that encapsulated the JMESPath rules for false. It's great that an important definition like that is not repeated over and over again.
However, I think the implementation for an often used function like this needs to take performance into account. Using literals in Ruby is problematic since they're allocated on each call, leading to unnecessary garbage being created.
I rewrote the code to avoid allocations, and also simplified it slightly.
These are benchmarks for a few different inputs before these changes (the full benchmark code is below).
And these are the numbers with the changes applied:
Notice especially the difference for the non-empty array hash cases. Checking that a hash is empty is much better than checking whether or not it is equal to another hash.
The benchmarks of course don't capture the most important aspect of this, GC pressure.
This is the full benchmark code:
We're have systems that are doing thousands, of not tens of thousands of JMESPath searches per second, so every little bit of performance counts.