Skip to content

fix: EXC: Fix memory_bytes#5813

Closed
berestovskyy wants to merge 2 commits intomasterfrom
andriy/fix-memory-bytes
Closed

fix: EXC: Fix memory_bytes#5813
berestovskyy wants to merge 2 commits intomasterfrom
andriy/fix-memory-bytes

Conversation

@berestovskyy
Copy link
Copy Markdown
Contributor

@berestovskyy berestovskyy commented Jul 3, 2025

The PR fixes the memory_bytes getters around the codebase.

The implementation takes care of determinism (by using deterministic len) and performance (by not calculating the deep Vec or BTreeSet sizes).

Due to the above, the size calculated by the memory_bytes is still an estimation, not an exact value.

The PR also adds a few tests to future-proof the size calculations in query cache.

@github-actions github-actions Bot added the fix label Jul 3, 2025
@berestovskyy berestovskyy force-pushed the andriy/fix-memory-bytes branch from 5005a47 to 3155802 Compare July 3, 2025 07:47
The PR fixes the `memory_bytes` getters around
the codebase.

The implementation takes care of determinism
(by using deterministic `len`) and performance
(by not calculating the deep `Vec` or `BTreeSet`
sizes).

Due to the above, the size calculated by the
`memory_bytes` is still an estimation, not
an exact value.

The PR also adds a few tests to future-proof
the size calculations in query cache.
@berestovskyy berestovskyy force-pushed the andriy/fix-memory-bytes branch from 3155802 to e446659 Compare July 3, 2025 07:54
@berestovskyy berestovskyy marked this pull request as ready for review July 3, 2025 12:42
@berestovskyy berestovskyy requested review from a team as code owners July 3, 2025 12:42
Copy link
Copy Markdown
Contributor

@mraszyk mraszyk left a comment

Choose a reason for hiding this comment

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

The comment about shallow vs deep estimate is more general: what's the strategy to decide between shallow vs deep estimates?

The point regarding using { .. } applies throughout.

Comment thread rs/types/types/src/lib.rs
impl MemoryDiskBytes for Time {
/// Returns the total number of bytes that this object occupies
/// in stack and heap memory.
fn memory_bytes(&self) -> usize {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ideally we'd make this implementation "frozen" so that people can't override it, but I guess that is not possible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not as a trait, but as a public function:

deterministic_total_bytes(&obj);

vs now with trait:

obj.deterministic_total_bytes();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

WDYT?

Comment thread rs/types/types/src/lib.rs
Comment thread rs/types/types/src/lib.rs
Comment thread rs/types/wasm_types/src/errors.rs
Comment thread rs/execution_environment/src/query_handler/query_cache/tests.rs
Comment thread rs/execution_environment/src/query_handler/query_cache/tests.rs
@berestovskyy
Copy link
Copy Markdown
Contributor Author

Closing in favor of #6445

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants