Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pb): box stream NodeBody to reduce stack memory usage #19911

Merged
merged 8 commits into from
Dec 24, 2024
Merged

Conversation

xxchan
Copy link
Member

@xxchan xxchan commented Dec 24, 2024

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

fix #19910 See analysis in the issue

also revert #19695

Checklist

  • I have written necessary rustdoc comments.
  • I have added necessary unit tests and integration tests.
  • I have added test labels as necessary.
  • I have added fuzzing tests or opened an issue to track them.
  • My PR contains breaking changes.
  • My PR changes performance-critical code, so I will run (micro) benchmarks and present the results.
  • My PR contains critical fixes that are necessary to be merged into the latest release.

Documentation

  • My PR needs documentation updates.
Release note

@xxchan xxchan requested a review from a team as a code owner December 24, 2024 06:31
@xxchan xxchan requested a review from MrCroxx December 24, 2024 06:31
fn test_size() {
use static_assertions::const_assert_eq;

const_assert_eq!(std::mem::size_of::<NodeBody>(), 16);
Copy link
Member Author

Choose a reason for hiding this comment

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

4120 bytes -> 16 bytes

@@ -112,6 +112,57 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"#[derive(::enum_as_inner::EnumAsInner)]",
)
.btree_map(btree_map_paths)
// node body is a very large enum, so we box it to avoid stack overflow.
// TODO: ideally we should box all enum variants automatically https://github.com/tokio-rs/prost/issues/1209
.boxed(".stream_plan.StreamNode.node_body.source")
Copy link
Member

Choose a reason for hiding this comment

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

Why not .boxed(".stream_plan.StreamNode")?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds can also fix the stackoverflow. 🤔 But the enum itself still wastes memory.

Copy link
Member

Choose a reason for hiding this comment

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

Listing all possible variants here seems verbose. Is this the only approach to achieve the goal?

Copy link
Member Author

Choose a reason for hiding this comment

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

can implement this upstream tokio-rs/prost#1209

Copy link
Member

@stdrc stdrc left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@MrCroxx MrCroxx left a comment

Choose a reason for hiding this comment

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

LGTM

Signed-off-by: xxchan <[email protected]>
.boxed(".stream_plan.StreamNode.node_body.source")
.boxed(".stream_plan.StreamNode.node_body.project")
.boxed(".stream_plan.StreamNode.node_body.filter")
.boxed(".stream_plan.StreamNode.node_body.materialize")
Copy link
Contributor

@chenzl25 chenzl25 Dec 24, 2024

Choose a reason for hiding this comment

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

Shall we box the batch plan node as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

batch node body was 680 bytes. After boxing Udf in Expr, it's 464 bytes. Sounds acceptable

Copy link
Member Author

Choose a reason for hiding this comment

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

LocalLookupJoinNode is the largest

@@ -112,6 +112,57 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"#[derive(::enum_as_inner::EnumAsInner)]",
)
.btree_map(btree_map_paths)
// node body is a very large enum, so we box it to avoid stack overflow.
// TODO: ideally we should box all enum variants automatically https://github.com/tokio-rs/prost/issues/1209
.boxed(".stream_plan.StreamNode.node_body.source")
Copy link
Member

Choose a reason for hiding this comment

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

Listing all possible variants here seems verbose. Is this the only approach to achieve the goal?

src/prost/src/lib.rs Show resolved Hide resolved
Signed-off-by: xxchan <[email protected]>
Signed-off-by: xxchan <[email protected]>
@xxchan xxchan enabled auto-merge December 24, 2024 16:15
@xxchan xxchan added this pull request to the merge queue Dec 24, 2024
@graphite-app graphite-app bot requested a review from a team December 24, 2024 16:59
Merged via the queue into main with commit ef5835e Dec 24, 2024
31 of 32 checks passed
@xxchan xxchan deleted the xxchan/prost branch December 24, 2024 17:00
xxchan added a commit that referenced this pull request Dec 24, 2024
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.

frontend stack overflow at stream fragmenter
8 participants