Skip to content

Reduce size of Expr struct #16199

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

Closed
alamb opened this issue May 27, 2025 · 6 comments · Fixed by #16207
Closed

Reduce size of Expr struct #16199

alamb opened this issue May 27, 2025 · 6 comments · Fixed by #16207
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@alamb
Copy link
Contributor

alamb commented May 27, 2025

Is your feature request related to a problem or challenge?

For unrelated reasons, I reduced the size of Expr from 272 to 112 bytes in this PR:

It turns out this change resulted in a a pretty significant (10-20% faster) improvement in planning time #14366 (comment):

group                                         alamb_make_expr_smaller                main
-----                                         -----------------------                ----
physical_plan_clickbench_all                  1.00    285.4±4.98ms        ? ?/sec    1.14    324.2±6.52ms        ? ?/sec
physical_plan_clickbench_q1                   1.00      4.6±0.12ms        ? ?/sec    1.10      5.0±0.13ms        ? ?/sec
physical_plan_clickbench_q10                  1.00      5.7±0.14ms        ? ?/sec    1.16      6.5±0.42ms        ? ?/sec
physical_plan_clickbench_q11                  1.00      5.8±0.22ms        ? ?/sec    1.13      6.6±0.21ms        ? ?/sec
physical_plan_clickbench_q12                  1.00      6.0±0.17ms        ? ?/sec    1.12      6.7±0.24ms        ? ?/sec
physical_plan_clickbench_q13                  1.00      5.5±0.11ms        ? ?/sec    1.12      6.1±0.17ms        ? ?/sec
physical_plan_clickbench_q14                  1.00      5.8±0.17ms        ? ?/sec    1.12      6.5±0.15ms        ? ?/sec
physical_plan_clickbench_q15                  1.00      5.6±0.14ms        ? ?/sec    1.13      6.3±0.18ms        ? ?/sec
physical_plan_clickbench_q16                  1.00      5.1±0.18ms        ? ?/sec    1.09      5.5±0.19ms        ? ?/sec
physical_plan_clickbench_q17                  1.00      5.0±0.13ms        ? ?/sec    1.14      5.8±0.15ms        ? ?/sec
physical_plan_clickbench_q18                  1.00      4.9±0.13ms        ? ?/sec    1.12      5.4±0.15ms        ? ?/sec
...

Describe the solution you'd like

I would like to make a new PR that reduces the size of Expr

Describe alternatives you've considered

I suggest

  1. Change Expr::WindowFunction(WindowFunction) --> Expr::WindowFunction(Box<WindowFunction>) as described on Reduce size of Expr struct #14366
  2. Add a regression test for Expr size to ensure we don't get a regression again

Additional context

I recommend:

  1. Updating the Expr::WindowFunction definition
  2. Letting the compiler guide you to code that needs to be updated and follow the pattern from Reduce size of Expr struct #14366
  3. Copy the tests from Reduce size of Expr struct #14366
@alamb alamb added the enhancement New feature or request label May 27, 2025
@alamb alamb added the good first issue Good for newcomers label May 27, 2025
@alamb
Copy link
Contributor Author

alamb commented May 27, 2025

I think this is a good first issue because

  1. there is an example / pattern to follow
  2. There is evidence that this will make significant improvements

@hendrikmakait
Copy link
Contributor

take

@alamb
Copy link
Contributor Author

alamb commented May 27, 2025

Thanks @hendrikmakait !

@Omega359
Copy link
Contributor

I am surprised by the magnitude of the performance uptick by essentially moving something from the stack to the heap.

@alamb
Copy link
Contributor Author

alamb commented May 27, 2025

I am surprised by the magnitude of the performance uptick by essentially moving something from the stack to the heap.

My theory is that the performance difference is not the move to the heap but the fact that then all the places that make Exprs and copy them, etc have less work to do (as the Expr struct is half the size)

@Omega359
Copy link
Contributor

🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants