Repository navigation
Read only the parts of the JSON input that the query can inspect - #87
Merged
Merged
Conversation
* origin/main: Speed up interpreter hot paths and JSON rendering (#72) Fit the playground to the viewport and move the share button next to the query (#81) Make ? give no output on a type mismatch and stop hiding undefined functions (#83) Move .cursor documents to docs and stop tracking .cursor (#84) # Conflicts: # README.md # cli/cli.ml # source/Core.ml
|
Caution Review failedThe pull request is closed.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
davesnx
marked this pull request as ready for review
November 10, 2026 10:47
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.
The query is now analysed before the input is read. The reader builds only the parts of the document that the query can inspect and validates the rest without allocation. Output, error text and exit codes do not change.
This revives the idea of #73 without its second evaluator: the interpreter is unchanged and runs on a pruned tree.
How it works
Demand.of_expressionturns the query into a description of what the reader must keep:.[] | .name.englishItems (Fields ["name", Fields ["english", All]])map({name, id})Items (Fields ["name", All; "id", All])map(.price) | addItems (Fields ["price", All])lengthItems Skipkeys,., any query withfnAllAll), so the parts of the query before it still narrow the read..[] | f,map(f),[.[] | f]or.on an array is evaluated one element at a time: read, runf, render into the output buffer, drop. The output is still held until the whole input is valid and the query has succeeded.New flag
--stream-outputprints each result of a root.[] | fwhen its element is read. The first query error orhaltends the run at once. A JSON error found later follows the results already printed.Measurements
hyperfine -N --warmup 2, 10 runs, mean ± σ in ms, on a 21 MB array of 97,080 objects, x86_64 Linux. Base isd001076(main), head iscde94a2, both built with--profile=release. The machine had other load, so read differences below 10% as noise..[] | .name.englishmap(.base.Attack)map(select(.base.Attack > 100) | .name.english)map({name: .name.english, hp: .base.HP})map(.base.Attack) | addsort_by(.base.Attack) | lengthlength.[].keysPeak memory (
/usr/bin/time, one run):.[] | .name.english160 MB to 8 MB,map(.base.Attack)152 MB to 8 MB,length152 MB to 12 MB,.[]217 MB to 40 MB,.250 MB to 74 MB.A query that needs the whole document at once (
keys,sort_by(.x)) gets nothing from this change.Checks
source/test/Test_demand.ml), and checks the reader rules directly (source/jotason/test/Test_demand.ml).Review notes
source/Demand.ml(the rules), thenvalue_dandfields_dinsource/jotason/Read.ml, thenCore.run_output.fnis read in full, because a definition can shadow a built-in that the analysis knows.-nand the REPL are unchanged.--stream-outputon Windows and with a closed stdout.Risk: two-way door. A revert restores the full read for every query and removes
--stream-output; no data or format changes.