Keep generated registry dispatch JIT-compilable and remove dead code (0.13.0) - #64
Merged
Merged
Conversation
The generated TemplateSet kept the index switch and the subclass instanceof chain in one render method. From about 215 templates that method exceeds HotSpot's 8000-byte huge-method limit and is never JIT-compiled; ReAI's web-app registry (353 templates, 13,137 bytes) paid about 190 ns per render instead of about 10 ns. Dispatch now goes through a small render method, 256-template chunk methods and a separate subclass fallback. Also removes the unused HtmlOutput.url, RouteCatalog.isEmpty, a test-only constructor and an unused import, compiles naming regexes once, and corrects stale versions and statuses in the docs. Releases as 0.13.0. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Why
The generated
TemplateSet.renderkept the class-index switch and the subclassinstanceoffallback chain in one method. That costs about 37 bytes of bytecode per template. From roughly 215 templates the method exceeds HotSpot's 8000-byteHugeMethodLimit, and with the default-XX:+DontCompileHugeMethodsit is never JIT-compiled.ReAI's web-app registry has 353 templates and a 13,137-byte
render. ReAI's Dockerfile doesn't override the flag, so every production render currently runs through an interpreted dispatch.JMH replica of the generated shape at 353 templates (M5 Max, JDK 27, 3 forks). The host was under unrelated load, which widens the interpreted error:
render)-XX:-DontCompileHugeMethods(control)The control run shows the whole difference comes from the method being interpreted. ReAI pages render in about 6–40 µs, so this removes roughly 0.5–3% per request, with no trade-off.
What
RegistryGenerator, same asMessageGeneratorandRouteGenerator):renderis now a small dispatcher that looks up the index and switches onindex / 256into private chunk methods of at most about 4 KB each.instanceofchain moves torenderSubtype.isAssignableFromchain moves toisSupertypeOfModel.isOpen()can't see all-open compiler plugins or Java library classes, so dropping "final" models would not be provably safe.HtmlOutput.url(TrustedUrl)was never called by generated code or by any consumer, and calling it directly skipped context-path resolution.RouteCatalog.isEmpty().SpringRequestDataValuesconstructor; the test now usescreate(...).TaskProviderimport.Validation
./gradlew buildpasses, including the example golden renders.RegistryGeneratorTestcompiles a 600-template registry (3 chunks) plus an open model with a subclass. It renders every model, checkssupports,supportsReturnTypeandusesRequestDataValuesplus the unknown-model error, and asserts every per-request method is under 8000 bytes. The test fails when the chunking is disabled.ThimTemplates.javadiffers. All 32ThimTemplatesPart*.javafiles, their.binresources and the message usage manifest are byte-identical. With the candidate, the largest ReAI registry methods arerenderSubtypeat 6,727 bytes andrender0at 4,127 bytes;renderis 108 bytes.-PthimBuild.Considered and left out
getRuntimeClasses()in settings-plugin looks unused but is a public task property, so it's not provably unused.🤖 Generated with Claude Code