Repository navigation
perf(workflow-core): reuse one SizeOf engine for tuple sizing - #9618
Draft
Matthew-DWM wants to merge 2 commits into
Draft
Matthew-DWM wants to merge 2 commits into
Matthew-DWM wants to merge 2 commits into
Conversation
Tuple.inMemSize is the byte charge that flow control, operator statistics and the Python worker queue rely on. Pin it before changing how it is computed: each new TupleSpec case compares a tuple's charge with what a brand-new SizeOf engine reports for the same tuple, across every attribute type, objects shared within a row, ANY values with cycles and nested tuples, the snapshot taken at construction, Attribute and Schema subclass state, and rows built concurrently. A FlowControlSpec case pins admission of a frame of real tuples at exactly its credit, and stashing one byte short.
Tuple computed inMemSize with SizeOf.newInstance().deepSizeOf(this), so every row built a new sizing engine. On JDK 17 the library cannot attach its agent to the running JVM, so each newInstance() built an AgentSizeOf, caught the UnsupportedOperationException it threw, then built an UnsafeSizeOf, and the walk that followed rebuilt reflection caches for every class it reached. Tuple now keeps one engine in its companion object and still calls deepSizeOf(this) eagerly in the constructor, so each row's charge is the same. deepSizeOf keeps each walk's traversal state local to the call and caches only per-class facts in concurrent maps, so the shared engine is thread-safe.
Contributor
Automated Reviewer SuggestionsBased on the
|
Matthew-DWM
marked this pull request as draft
November 23, 2026 17:49
This branch has not been deployed
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.
What changes were proposed in this PR?
TuplecomputedinMemSizewithSizeOf.newInstance().deepSizeOf(this), so every row built a new sizing engine. On JDK 17 thesizeoflibrary can't attach its agent, so each call first built anAgentSizeOfthat throws, then anUnsafeSizeOf, and every new engine started with empty reflection caches.Tuplenow keeps one engine in its companion object and still callsdeepSizeOf(this)when a row is built. The walk is the same, so every row'sinMemSize(used by flow control, operator statistics and the Python worker queue) is unchanged. EachdeepSizeOfcall keeps its own traversal state and the caches are thread-safe, so workers can share the engine.Local workflow runs (median of several runs):
mainTradeoff: the engine's soft reflection cache can keep classes compiled at runtime (for example a Java UDF) loaded until memory runs low. It never holds row values.
Any related issues, documentation, discussions?
Closes #9617.
Related: #9614, which makes the same
inMemSizeline lazy.How was this PR tested?
TupleSpeccases check thatinMemSizeequals what a brand-newSizeOfengine reports for: every attribute type, objects shared within a row,ANYvalues with cycles and nested tuples, the size taken at construction,Attribute/Schemasubclass state, and 8 threads building rows at once. A newFlowControlSpeccase sends a frame of real tuples at exactly its credit and stashes it one byte short. All new cases pass onmainand with this change; a lazily computed size or a cached schema size makes some of them fail.182 and 52 tests pass; lint is clean.
skip-integration) and integration suites of every module that depends onWorkflowCoregive the same results as onmain.mainand this PR in separate JVMs (different JVM memory layouts,sizeof0.4.3 and 0.4.4, 8 threads): identical.Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Opus 5.5)