Skip to content

Unbox values#925

Merged
tyt2y3 merged 8 commits intoSeaQL:masterfrom
Huliiiiii:unbox-value
Jul 30, 2025
Merged

Unbox values#925
tyt2y3 merged 8 commits intoSeaQL:masterfrom
Huliiiiii:unbox-value

Conversation

@Huliiiiii
Copy link
Copy Markdown
Member

@Huliiiiii Huliiiiii commented Jul 28, 2025

PR Info

Unbox values, benchmarks show a 10–15% performance improvement in query construction

  • Dependencies:
  • Dependents:

New Features

Bug Fixes

Breaking Changes

  • values inside the Value enum are no longer boxed.

Changes

@tyt2y3 tyt2y3 requested a review from Expurple July 29, 2025 09:47
@tyt2y3
Copy link
Copy Markdown
Member

tyt2y3 commented Jul 29, 2025

shall we establish a new size bound for Value, may be constrainting to 24 bytes in total, and so any type making it larger should be boxed?

edit: I think reasonable max size is probably 32 bytes, then we can hold a Vec<T> or String, which are 24 bytes themselves.

@Expurple
Copy link
Copy Markdown
Member

We can just assert the current size for now. If a new variant appears, makes the enum larger and breaks the assertion, then we can benchmark and decide whether we need to box that new variant

Copy link
Copy Markdown
Member

@Expurple Expurple left a comment

Choose a reason for hiding this comment

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

Thank you, looks cleaner this way.

Can you also fix the CI errors and add a changelog entry?

@tyt2y3
Copy link
Copy Markdown
Member

tyt2y3 commented Jul 29, 2025

I'd probably add this:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=d65d5efec03c1751464e479bb0541f21

const _: () = {
    check_value_size();
};

const fn check_value_size() {
    if std::mem::size_of::<Value>() > 32 {
        panic!("the size of Value shouldn't be greater than 32 bytes")
    }
}

@Expurple
Copy link
Copy Markdown
Member

I'd also add a comment right there, next to the assertion. To document our approach and the existence of the benchmark

@Huliiiiii Huliiiiii force-pushed the unbox-value branch 2 times, most recently from 646064f to a5d42ea Compare July 29, 2025 16:57
@Huliiiiii
Copy link
Copy Markdown
Member Author

Huliiiiii commented Jul 29, 2025

Based on the benchmark results, I didn't see any performance impact from the size of Value (24 vs 40). I think the heap allocation would have a larger performance overhead.

@tyt2y3
Copy link
Copy Markdown
Member

tyt2y3 commented Jul 29, 2025

@Huliiiiii I agree with you. object in heap is almost always worse than on stack. but I think we should put a guard in place to prevent it growing unchecked.

Copy link
Copy Markdown
Member

@Expurple Expurple left a comment

Choose a reason for hiding this comment

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

Still needs a changelog entry. LGTM otherwise

Comment thread tests/size.rs
Huliiiiii and others added 3 commits July 30, 2025 13:19
@tyt2y3 tyt2y3 merged commit f985330 into SeaQL:master Jul 30, 2025
20 checks passed
@tyt2y3
Copy link
Copy Markdown
Member

tyt2y3 commented Jul 30, 2025

I'll probably make some small tweaks

@Huliiiiii Huliiiiii deleted the unbox-value branch July 31, 2025 22:34
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.

3 participants