Skip to content

refactor: reduce watchmap memory size#92

Merged
wolfv merged 1 commit intoprefix-dev:mainfrom
baszalmstra:refactor/watch_map_size
Jan 2, 2025
Merged

refactor: reduce watchmap memory size#92
wolfv merged 1 commit intoprefix-dev:mainfrom
baszalmstra:refactor/watch_map_size

Conversation

@baszalmstra
Copy link
Copy Markdown
Contributor

Reduce the memory consumption of the WatchMap by utilizing NonZeroU32. Rust has an optimization that an Option<NonZero..> is the same size as a NonZero... The optimization uses the fact that 0 means None.

Our Mapping type stores Option<T>. The WatchMap contains a Mapping<Literal, ClauseId>. For each Literal we store an Option<ClauseId>. Previously we would encode a null clause as ClauseId::null. We now store this as an Option<ClauseId>.

This reduces the memory size of an Option<ClauseId> from 8 bytes to 4 bytes. It reduces the memory usage of the watchmap by 50% and makes working with a null clause more ergonomic.

I didnt run the benchmarks but I am quite confident that there will be no negative impact.

@baszalmstra baszalmstra requested a review from wolfv January 1, 2025 11:30
@wolfv
Copy link
Copy Markdown
Member

wolfv commented Jan 1, 2025

Nice!

@wolfv wolfv merged commit f89c0b2 into prefix-dev:main Jan 2, 2025
@baszalmstra baszalmstra mentioned this pull request Dec 31, 2024
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.

2 participants