Skip to content

Optimize JRT.compare2 hot paths and publish benchmark reports#477

Open
bertysentry wants to merge 1 commit into
mainfrom
475-optimize-jrtcompare2object-object-boolean-hot-paths
Open

Optimize JRT.compare2 hot paths and publish benchmark reports#477
bertysentry wants to merge 1 commit into
mainfrom
475-optimize-jrtcompare2object-object-boolean-hot-paths

Conversation

@bertysentry
Copy link
Copy Markdown
Contributor

Summary

  • Fast-path common compare2 operand shapes in JRT and avoid exception-driven numeric coercion on the hot path.
  • Add focused unit coverage for comparison semantics and comparison-number detection, including rejected hex forms.
  • Add a JMH benchmark suite for compare2 and publish release benchmark data through GitHub Pages.
  • Add a dedicated benchmark documentation page that loads published JSON in the browser and updates the site navigation.

Testing

  • mvn license:update-file-header formatter:format verify site
  • Local browser verification of the generated benchmarks.html with sample benchmark JSON

Copy link
Copy Markdown

@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: 5677cf8eef

ℹ️ 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".

Comment on lines +689 to +690
} else if (isComparisonNumber(o1String)) {
o1Number = new BigDecimal(o1String).doubleValue();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Guard BigDecimal coercion for numeric-string comparisons

isComparisonNumber() accepts arbitrarily long exponents, but the subsequent new BigDecimal(o1String) call is now unguarded; inputs like "1e2147483649" pass the predicate and then throw NumberFormatException (exponent overflow). Before this change, the conversion was inside a try/catch and compare2 fell back to string comparison, so this is a regression that can crash comparisons on malformed or extreme numeric-looking fields instead of evaluating them.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes io.jawk.jrt.JRT.compare2 for common operand shapes (especially numeric comparisons), introduces a comparison-number fast check to avoid exception-driven coercion on hot paths, and adds the infrastructure to benchmark and publish those results via the Maven site + GitHub Pages.

Changes:

  • Fast-path numeric vs numeric comparisons in compare2 and add isComparisonNumber for cheap numeric-string detection.
  • Add unit tests covering numeric, numeric-string, mixed, and fallback string-comparison semantics.
  • Add a JMH benchmark suite and a GitHub Actions workflow + site page to publish and display benchmark reports.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/main/java/io/jawk/jrt/JRT.java Optimizes compare2 hot paths; introduces isComparisonNumber helper.
src/test/java/io/jawk/JRTTest.java Adds focused compare2 semantic tests.
src/test/java/io/jawk/jrt/JRTComparisonNumberTest.java Adds unit tests for isComparisonNumber acceptance/rejection cases (incl. hex rejection).
src/jmh/java/io/jawk/jrt/JRTCompare2Benchmark.java Adds JMH microbenchmarks for common compare2 operand shapes.
pom.xml Adds JMH version + benchmark profile; wires JMH sources into formatting/licensing and build steps.
src/site/xhtml/benchmarks.xhtml Adds a benchmarks documentation page intended to load/present published JSON results.
src/site/site.xml Adds navigation entry to the new benchmarks page.
src/site/resources/css/site.css Adds styling for the benchmarks page layout/table.
CONTRIBUTING.md Documents how to build/run benchmarks and how publishing works.
.github/workflows/benchmarks.yml Adds a workflow to run JMH on tags/dispatch, update the site JSON index, and publish to GitHub Pages.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +34 to +38
function renderTemplate(host) {
host.innerHTML = [
'<div ng-controller="BenchmarkController as vm" ng-cloak="">',
' <div class="alert alert-info" ng-if="vm.loading">Loading published benchmark index...</div>',
' <div class="alert alert-warning" ng-if="vm.error">{{vm.error}}</div>',
Comment on lines +683 to 685
if (o1String.equals(o2String)) {
return mode == 0;
}
Comment on lines +247 to +251
const content = await getText(new URL(normalizedPath, siteBase));
if (content === null) {
return;
}
const outputPath = path.join(siteRoot, normalizedPath);
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.

Optimize JRT.compare2(Object, Object, boolean) hot paths

2 participants