-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Reduce size of Expr
from 80 to 64 bytes
#9900
Conversation
e39e102
to
65e91b1
Compare
CodSpeed Performance ReportMerging #9900 will improve performances by 4.49%Comparing Summary
Benchmarks breakdown
|
That's a bit better... |
I think I can do even better though. |
b9f9008
to
1a64522
Compare
Okay, there's no longer any parser regression, and there are parser and linter improvements across the board (though many don't meet our threshold). |
1a64522
to
ecf5a10
Compare
ecf5a10
to
2543f3d
Compare
2543f3d
to
b387317
Compare
pub args: Vec<Expr>, | ||
pub keywords: Vec<Keyword>, | ||
pub args: Box<[Expr]>, | ||
pub keywords: Box<[Keyword]>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could make these Option<Box<...>>
to avoid allocating when empty...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be possible to use Option
without increasing the struct size, and avoiding the allocation could be nice. although It doesn't seem that the empty slice allocates
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gasp...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that is interesting. I actually couldn't find how this was being done in std specifically. So it could just be an optimization in the code generator somewhere. Or perhaps I missed a call to dangling
.
pub ops: Vec<CmpOp>, | ||
pub comparators: Vec<Expr>, | ||
pub ops: Box<[CmpOp]>, | ||
pub comparators: Box<[Expr]>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are never empty so zero-length slice is not a problem.
crates/ruff_python_ast/src/nodes.rs
Outdated
// static_assertions::assert_eq_size!(ExprTuple, [u8; 40]); | ||
// static_assertions::assert_eq_size!(ExprUnaryOp, [u8; 24]); | ||
// static_assertions::assert_eq_size!(ExprYield, [u8; 16]); | ||
// static_assertions::assert_eq_size!(ExprYieldFrom, [u8; 16]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MichaReiser - I missed your comment when we talked in-person -- did you want me to include these as assert!
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry. I don't mind keeping them. I do find them useful when analyzing the type's size in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Master of the double-star.
crates/ruff_linter/src/rules/flake8_pyi/rules/bad_version_info_comparison.rs
Show resolved
Hide resolved
0863c48
to
3d93f59
Compare
3d93f59
to
708ef73
Compare
crates/ruff_linter/src/rules/flake8_pyi/rules/bad_version_info_comparison.rs
Show resolved
Hide resolved
pub args: Vec<Expr>, | ||
pub keywords: Vec<Keyword>, | ||
pub args: Box<[Expr]>, | ||
pub keywords: Box<[Keyword]>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be possible to use Option
without increasing the struct size, and avoiding the allocation could be nice. although It doesn't seem that the empty slice allocates
|
## Summary This PR reduces the size of `Expr` from 80 to 64 bytes, by reducing the sizes of... - `ExprCall` from 72 to 56 bytes, by using boxed slices for `Arguments`. - `ExprCompare` from 64 to 48 bytes, by using boxed slices for its various vectors. In testing, the parser gets a bit faster, and the linter benchmarks improve quite a bit.
Summary
This PR reduces the size of
Expr
from 80 to 64 bytes, by reducing the sizes of...ExprCall
from 72 to 56 bytes, by using boxed slices forArguments
.ExprCompare
from 64 to 48 bytes, by using boxed slices for its various vectors.In testing, the parser gets a bit faster, and the linter benchmarks improve quite a bit.