GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Cache immutable literals in indy JIT by headius · Pull Request #9644 · jruby/jruby

Conversation

@headius

@headius headius commented Sep 3, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Immutable literal values like numerics and ranges can be created once globally and never constructed again. Without a global cache, however, both the IR and the JIT will potentially construct them more than once, even if those values may be locally cached. In addition, the IR optimizer will sometimes propagate immutable literal values through variables and copies making it appear that there are multiple of the same literal in a piece of code. This all combines to potentially create more instances of immutable literal values than the single global value actually needed.

This PR introduces a global cache for several immutable literal values using an object key and a weak-valued map. So long as one piece of code remains loaded and referencing a given value, it should not be recreated in duplicate operands or call sites. This cache acts as a sort of constant pool for these values.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@headius headius added this to the JRuby 10.1.2.0 milestone Sep 3, 2026
@headius
headius force-pushed the cache_immutable_literals branch 3 times, most recently from 079cf90 to 6c83f28 Compare September 4, 2026 01:03
@headius
Introduce a cache for immutable literal values
b8f89b9
Immutable literal values like numerics and ranges can be created
once globally and never constructed again. Without a global cache,
however, both the IR and the JIT will potentially construct them
more than once, even if those values may be locally cached. In
addition, the IR optimizer will sometimes propagate immutable
literal values through variables and copies making it appear that
there are multiple of the same literal in a piece of code. This all
combines to potentially create more instances of immutable literal
values than the single global value actually needed.

This PR introduces a global cache for several immutable literal
values using an object key and a weak-valued map. So long as one
piece of code remains loaded and referencing a given value, it
should not be recreated in duplicate operands or call sites. This
cache acts as a sort of constant pool for these values.
@headius
headius force-pushed the cache_immutable_literals branch from 6c83f28 to b8f89b9 Compare September 4, 2026 02:23
@headius

headius commented Sep 4, 2026

Copy link
Copy Markdown
Member Author

This is a simple way to handle caching immutable literals but I need to run some tests to make sure it does not increase memory size. Where before there might have been two RubyFloat with the same value, now there will be one RubyFloat plus a Double key and a WeakReference holder along with whatever bookkeeping objects are required inside WeakValuedMap. For values repeated in many places, this will be a savings, but for values that only appear a few times in code, we may actually be using more memory.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@headius headius mentioned this pull request Sep 4, 2026
Consider encoding in ByteList equality #9646
Open
@kares

kares commented Sep 4, 2026

Copy link
Copy Markdown
Member

what's the motivation behind this, does this matter in production apps?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@headius

headius commented Sep 10, 2026

Copy link
Copy Markdown
Member Author

@kares I don't have an answer to that. I do know that it surfaced a bug when I started re-enabling non-indy test runs #9643. It is of debatable utility, though, which is why I commented above that the overhead of this system may not be worth any small benefit.

It is arguably similar to a constant pool, which JVM classes typically do on a per-classfile basis, or deduplicated Strings in the JVM. But at the JVM level they can implement weak caches much more efficiently.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@headius headius removed this from the JRuby 10.1.2.0 milestone Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@headius @kares
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.