perf(vm): lazily clone the type-check cache per transaction#5901
Draft
omarsy wants to merge 1 commit into
Draft
Conversation
MakeGnoTransactionStore ran maps.Clone(vm.typeCheckCache) on every transaction via the BeginTxHook, but only AddPackage and Run consume the cache — MsgCall and query eval, the common case, never type-check. Every such transaction paid for a full clone of the shared cache (~stdlib package count) and threw it away unused. Store a holder that clones on first access instead. The clone is created at most once per transaction and shared across a tx's messages, so multi-message AddPackage transactions behave exactly as before; transactions that never type-check now skip the clone entirely. Pure node-side work reduction — no consensus- or gas-visible change.
Collaborator
🛠 PR Checks SummaryAll Automated Checks passed. ✅ Manual Checks (for Reviewers):
Read More🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers. ✅ Automated Checks (for Contributors):🟢 Maintainers must be able to edit this pull request (more info) ☑️ Contributor Actions:
☑️ Reviewer Actions:
📚 Resources:Debug
|
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.
Summary
MakeGnoTransactionStoreranmaps.Clone(vm.typeCheckCache)on every transaction (via theBeginTxHook), but onlyAddPackageandRunever consume that cache —MsgCalland query eval, the common case, never type-check. Every such transaction paid for a full clone of the shared cache (~stdlib package count) and discarded it unused.This stores a small holder that clones lazily on first access instead:
Transactions that never type-check skip the clone entirely;
AddPackage/Runstill get exactly one clone, shared across a tx's messages.Why it's safe (no consensus / gas / behavior change)
SetPreprocessAllocator/SetGasMeterrun afterward), so it never consumed tx gas in either the old or new code. No gas goldens change.BeginTxHookfires once per transaction, so all messages in a tx share one holder → one clone, identical to the previous eager behavior.base(vm.typeCheckCache, only written at init/restart); the consumer writes to the clone, neverbase.go test -race.Impact
Pure node-side work reduction: eliminates one
maps.Cloneof the shared type-check cache for every non-type-checking transaction (the majority). No user-visible or consensus-visible effect.Changed files
gno.land/pkg/sdk/vm/keeper.go— lazy holder + accessor (20 lines).Verification
go test ./gno.land/pkg/sdk/vm/✅go test -race ./gno.land/pkg/sdk/vm/✅gofmt/go vetclean🤖 Generated with Claude Code