perf: Avoid constructor setup during resolve#2211
Merged
Conversation
alexander-fenster
approved these changes
May 1, 2026
Merged
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.
Resolving fields currently reads
parent.ctorto install prototype defaults. Sincectoris a lazy getter, this also generates a runtime message constructor for every resolved type. That constructor setup then resolves the same fields again.This PR separates reflection resolution from runtime constructor initialization:
Field#resolveupdates prototype defaults only for constructors that already exist, avoiding the lazyctorgetter.Type#ctorinitializes prototype defaults when a constructor is actually created or registered.ctorinstead of creating a second one.On a synthetic benchmark with many cross-type references, this removes one redundant field-resolution pass and avoids generating constructors during schema loading, improving
fromJSONby roughly 40-50% depending on schema size.For
1500 types x 4 refs, the median localfromJSONtime went from 9.150ms to 4.855ms. The relevant call counts changed from 12000 to 6000Field#resolvecalls and from 1500 generated constructors during load to 0.So instead of rolling back eager resolution as proposed in #2157, this keeps the current eager semantics while reducing redundant work.
Follow-up to #2066 and #2068
Addresses #2123