Skip to content

Use the whole AST as key cache (close #708) - #710

Merged
flash-gordon merged 2 commits into
mainfrom
cache-keys-by-eql
Oct 5, 2026
Merged

flash-gordon merged 2 commits into
mainfrom
cache-keys-by-eql

Conversation

@flash-gordon

@flash-gordon flash-gordon commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Most of the data in the AST is retained anyway, so optimizing it with .hash doesn't buy much in practice (I've tested it on my projects). The other problem with the cache is that it can grow indefinitely, in theory. If an app produces dynamic queries using combines/select, etc the memory for AST and interim structs will be retained, but it's a separate problem; the current implementation is vulnerable just as well.

Most of the data in the AST is being retained anyway so trying to optimize it with .hash doesn't buy much in practice (I've tested it on my projects). The other problem with the cache is it can grow indefinitely, in theory. If an app produces dynamic queries using combines/select etc the memory for AST and interim structs will be retained but it's a separate problem, the current implementation is vulnerable just as well.
@flash-gordon
flash-gordon changed the base branch from main to release-5.4 October 5, 2026 10:56

@timriley timriley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @flash-gordon! I wasn't confident enough to know whether retaining the objects as the keys would be an issue, but if you're comfortable with this, it looks good to me 👍🏼

@timriley

timriley commented Oct 5, 2026

Copy link
Copy Markdown
Member

Is it worth filing an issue about the unbounded cache?

@flash-gordon

Copy link
Copy Markdown
Contributor Author

@timriley, conditionally, yes. The problem has to be justified against a possible solution. An agent can draft the approach so it's easier to decide whether we want to trade the added complexity for the corner case. What I found today is that the existence of the cache is 100% justified. Building a mapper for a complex query can easily take a few ms

@timriley
timriley changed the base branch from release-5.4 to main October 5, 2026 12:03
@timriley

timriley commented Oct 5, 2026

Copy link
Copy Markdown
Member

(FYI, I switched the base branch to main, since @citizen428 has just done a swap so that main is now equivalent to our previous release-5.4)

@flash-gordon
flash-gordon merged commit 07b18d1 into main Oct 5, 2026
4 checks passed
@flash-gordon
flash-gordon deleted the cache-keys-by-eql branch October 5, 2026 16:20
@timriley

timriley commented Oct 8, 2026

Copy link
Copy Markdown
Member

Looks like this fixed the rom-factory flakes! (After I updated the branches over in that Gemfile: hanakai-rb/rom-factory#101). Thanks @flash-gordon!

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