Skip to content

JsonPath runtime compilation#134

Open
simbo1905 wants to merge 5 commits intomainfrom
cursor/jsonpath-runtime-compilation-54b6
Open

JsonPath runtime compilation#134
simbo1905 wants to merge 5 commits intomainfrom
cursor/jsonpath-runtime-compilation-54b6

Conversation

@simbo1905
Copy link
Owner

This pull request contains changes generated by a Cursor Cloud Agent

Open in Cursor Open in Web

cursoragent and others added 3 commits February 2, 2026 00:23
Refactoring to prepare for runtime compilation support:
- JsonPath is now a sealed interface permitting JsonPathInterpreted and JsonPathCompiled
- JsonPathInterpreted contains the existing AST-walking evaluation logic
- JsonPathCompiled stub added for future bytecode-compiled implementation
- JsonPathCompiler stub added with in-memory compilation infrastructure
- All 100 existing tests pass unchanged

Next steps: Add tests and implementation for runtime-compiled JsonPath

Co-authored-by: simbo1905 <simbo1905@60hertz.com>
Added JDK compiler-based runtime compilation for JsonPath:

- JsonPathExecutor: Public functional interface for compiled executors
- JsonPathHelpers: Public utility class with helper methods for generated code
  (getPath, toComparable, compareValues, normalizeIdx, evaluateRecursiveDescent)
- JsonPathCompiler: Generates and compiles Java source code at runtime using
  javax.tools.ToolProvider for in-memory compilation
- JsonPathCompiled: Executes compiled JsonPath queries

Code generation covers all JsonPath features:
- Property access (dot and bracket notation)
- Array indexing (positive and negative)
- Array slicing (start:end:step, reverse)
- Wildcards (* on objects and arrays)
- Filters (exists, comparison, logical AND/OR/NOT)
- Unions (multiple indices or properties)
- Recursive descent (.. for all descendants)
- Script expressions (@.length-1 pattern)

Added comprehensive test suite (JsonPathCompilerTest) with 40 tests verifying
compiled paths produce identical results to interpreted paths.

All 140 tests pass.

To compile a JsonPath for optimal performance:
  JsonPath compiled = JsonPath.compile(JsonPath.parse("$.store.book[*].author"));
  List<JsonValue> results = compiled.query(json);

Co-authored-by: simbo1905 <simbo1905@60hertz.com>
Updated README.md:
- Added 'Runtime Compilation (Performance Optimization)' section
- Documents how to use JsonPath.compile() for hot paths
- Explains when to use compiled vs interpreted paths
- Notes compilation is idempotent

Updated AGENTS.md:
- Documented the sealed interface architecture
- Added new entry points for compilation-related classes
- Added guidance for maintaining code generation

Co-authored-by: simbo1905 <simbo1905@60hertz.com>
@cursor
Copy link

cursor bot commented Feb 2, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@gemini-code-assist
Copy link

Summary of Changes

Hello @simbo1905, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a major performance enhancement to the JsonPath library by enabling runtime compilation of JsonPath expressions. Instead of solely relying on an AST-walking interpreter, users can now compile their JsonPath queries into optimized Java bytecode. This allows for faster execution, particularly beneficial for 'hot path' scenarios where the same query is run against many JSON documents. The changes involve a significant refactoring of the internal architecture to support both interpreted and compiled execution modes, ensuring flexibility and performance gains.

Highlights

  • Runtime Compilation: Introduced a new feature allowing JsonPath expressions to be compiled into optimized Java bytecode at runtime, significantly improving performance for frequently executed queries.
  • Architectural Refactoring: The core JsonPath class has been refactored into a sealed interface, with two primary implementations: JsonPathInterpreted (the original AST-walking evaluator) and JsonPathCompiled (the new bytecode-compiled executor).
  • Code Generation and Compilation: Added JsonPathCompiler to generate Java source code from the JsonPath Abstract Syntax Tree (AST) and compile it in-memory using the JDK's javax.tools.ToolProvider API.
  • Helper Utilities: New utility classes JsonPathExecutor (a functional interface for compiled paths) and JsonPathHelpers (providing common evaluation logic for generated code) were introduced.
  • Comprehensive Testing: A new test suite, JsonPathCompilerTest, has been added to ensure that the compiled JsonPath expressions produce identical results to their interpreted counterparts across all supported features.
  • Documentation Updates: Updated README.md with usage instructions and benefits of runtime compilation, and AGENTS.md with detailed architectural notes for contributors.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a major new feature: runtime compilation of JsonPath expressions to bytecode for improved performance. The architecture is well-designed, using a sealed interface JsonPath with JsonPathInterpreted and JsonPathCompiled implementations. The code generation and in-memory compilation are handled cleanly. The changes are accompanied by extensive documentation and a new test suite to ensure correctness by comparing compiled and interpreted results.

I've found a critical bug in the code generation for recursive descent that could lead to incorrect results, along with some dead code and areas for improvement in error handling and documentation clarity. Overall, this is a great addition, and with a few fixes, it will be a solid feature.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cbdd23bfba

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

cursoragent and others added 2 commits February 2, 2026 00:51
…eter

Addresses review comment: For unsupported recursive descent targets like
$..[0:2], $..[?(@.x)], or $..['a','b'], the compiled code was incorrectly
adding the current node to results. The interpreter logs and returns no
matches for these cases.

Changed to generate a no-op comment instead of adding to results, which
matches the interpreter's semantics.

Co-authored-by: simbo1905 <simbo1905@60hertz.com>
Fixes:
1. Remove unused evaluateRecursiveDescentFull() method from JsonPathHelpers
2. Remove unused collectAtPath() method from JsonPathHelpers
3. Fix README example: use 'compiled'/'interpreted' instead of undefined 'path'
4. Clarify in README that only limited script expressions are supported
5. Throw UnsupportedOperationException for unsupported script expressions
   instead of silently ignoring them

All 140 tests pass.

Co-authored-by: simbo1905 <simbo1905@60hertz.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants