Skip to content

Comments

Remove ValueWithMetadata#1057

Merged
MichaReiser merged 2 commits intosalsa-rs:masterfrom
MichaReiser:remove-value-with-metadata
Jan 21, 2026
Merged

Remove ValueWithMetadata#1057
MichaReiser merged 2 commits intosalsa-rs:masterfrom
MichaReiser:remove-value-with-metadata

Conversation

@MichaReiser
Copy link
Contributor

@MichaReiser MichaReiser commented Jan 10, 2026

This might be too naive, but it's not clear to me what the benefit of ValueWithMetadata is.
It seems we can inline Value into ValueWithMetadata.

Closes #1053

Test plan

Verified that this reduces the struct memory usage (it's negligible over all but still)

master

TOTAL MEMORY USAGE: 164.69MB
    struct metadata = 11.23MB
    struct fields = 11.73MB
    memo metadata = 33.01MB
    memo fields = 108.72MB
QUERY COUNT: 68
STRUCT COUNT: 66

This PR

TOTAL MEMORY USAGE: 164.60MB
    struct metadata = 11.13MB
    struct fields = 11.72MB
    memo metadata = 33.01MB
    memo fields = 108.73MB
QUERY COUNT: 68
STRUCT COUNT: 66

When running ty on trio

@netlify
Copy link

netlify bot commented Jan 10, 2026

👷 Deploy Preview for salsa-rs processing.

Name Link
🔨 Latest commit c4d3778
🔍 Latest deploy log https://app.netlify.com/projects/salsa-rs/deploys/6970dbfcb64f2a0008c2b132

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 10, 2026

Merging this PR will not alter performance

✅ 13 untouched benchmarks


Comparing MichaReiser:remove-value-with-metadata (c4d3778) with master (5facdfd)

Open in CodSpeed

@MichaReiser MichaReiser marked this pull request as ready for review January 10, 2026 12:05
@MichaReiser MichaReiser requested a review from Veykril January 10, 2026 12:05
Copy link
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

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

Yea I think this is actually fine now. We used to exclusively borrow the user supplied value in some codepaths which would cause aliasing or the metadata fields requiring this weird split. But after rebasing the PR a couple times it seems those issues resolved themselves now, I at least do not see places where we run risk of aliasing by removing this split again now

@Veykril Veykril requested a review from ibraheemdev January 10, 2026 12:07
@Veykril
Copy link
Member

Veykril commented Jan 10, 2026

I'd like to have @ibraheemdev double check that observation though just in case :)

Copy link
Member

@ibraheemdev ibraheemdev left a comment

Choose a reason for hiding this comment

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

This seems fine to me. I slightly prefer having the split and being able to use an UnsafeCell on the shared value part, but this is also fine (and avoids the need for repr(packed)).

@MichaReiser
Copy link
Contributor Author

This seems fine to me. I slightly prefer having the split and being able to use an UnsafeCell on the shared value part, but this is also fine (and avoids the need for repr(packed)).

I wouldn't mind that as it at least makes clear why the split exists in the first place and gives us a chance to document what constraints must be upheld when reading or writing the field. Do we need the UnsafeCell for both the value and memos or would it be enough to wrap value?

@ibraheemdev
Copy link
Member

I'm not sure, I haven't looked at the invariants closely. I think it's fine to merge this for the memory usage improvements and leave a TODO for later, it's not a huge deal.

@MichaReiser MichaReiser enabled auto-merge January 21, 2026 14:00
@MichaReiser MichaReiser added this pull request to the merge queue Jan 21, 2026
Merged via the queue into salsa-rs:master with commit ee70ab6 Jan 21, 2026
8 of 12 checks passed
@MichaReiser MichaReiser deleted the remove-value-with-metadata branch January 21, 2026 14:18
@github-actions github-actions bot mentioned this pull request Jan 21, 2026
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.

Reduce memory usage of tracked struct by reducing padding

3 participants