Repository navigation
perf: avoid full-list copies for indexed var lookups - #71
Open
siddarthaboddu wants to merge 1 commit into
Open
siddarthaboddu wants to merge 1 commit into
siddarthaboddu wants to merge 1 commit into
Conversation
Read and normalize only the selected element for numeric indexes and dotted paths. Keep the ArrayLike fallback for other iterable inputs. Add read-count regression coverage for both lookup forms and verify numeric conversion and missing-index handling on primitive arrays.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Looking up
{"var":42}in anArrayListpreviously copied and normalized every element to return one value. Numeric and dotted lookups such as{"var":"items.42"}now read the indexed element directly from Java arrays andRandomAccesslists, then normalize that value. Other collection types continue to use the existing lookup path.Tests
All 112 tests passed on Java 8 and Java 21. A regression test checks that both rule forms return the value at index 42 with exactly one element read from a 64-element list. Another test covers primitive array access and the default value for a missing index.
Benchmark
Average time and allocation per call to
JsonLogic.applywith the cached rule{"var":0}and a prebuiltArrayList<Integer>.Compared
49995a7andbaa05ebusing JMH 1.37 on Corretto 21 with one thread, two JVM forks, a fixed 512 MB heap, and the GC profiler. Each fork ran two 500 ms warmup iterations and three 500 ms measurement iterations.