Skip to content

Shrink the size of Expr - #12610

Merged
IanManske merged 13 commits into
nushell:mainfrom
IanManske:shrink-expr
Apr 24, 2024
Merged

IanManske merged 13 commits into
nushell:mainfrom
IanManske:shrink-expr

Conversation

@IanManske

@IanManske IanManske commented Apr 21, 2024 •

Copy link
Copy Markdown
Member

Description

Continuing from #12568, this PR further reduces the size of Expr from 64 to 40 bytes. It also reduces Expression from 128 to 96 bytes and Type from 32 to 24 bytes.

This was accomplished by:

  • for Expr with multiple fields (e.g., Expr::Thing(A, B, C)), merging the fields into new AST struct types and then boxing this struct (e.g. Expr::Thing(Box<ABC>)).
  • replacing Vec<T> with Box<[T]> in multiple places. Exprs and Expressions should rarely be mutated, if at all, so this optimization makes sense.

By reducing the size of these types, I didn't notice a large performance improvement (at least compared to #12568). But this PR does reduce the memory usage of nushell. My config is somewhat light so I only noticed a difference of 1.4MiB (38.9MiB vs 37.5MiB).

@IanManske
IanManske marked this pull request as ready for review April 21, 2024 15:55

@sholderbach sholderbach left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You are really on a refactor train

Generally appreciate the named fields on the new AST types.

I have some nitpicks around construction.

Other than that some benchmark numbers for parsing something larger (e.g. also from nuon) may be useful here.

Comment thread crates/nu-protocol/src/ty.rs Resolved
Comment thread crates/nu-protocol/src/ty.rs Resolved
Comment thread crates/nu-protocol/src/ast/expr.rs Resolved
Comment thread crates/nu-protocol/src/ast/table.rs Resolved
Comment thread crates/nu-parser/src/parser.rs Resolved
Comment thread crates/nu-protocol/src/ast/expr.rs Resolved
Co-authored-by: Stefan Holderbach <[email protected]>
@sholderbach sholderbach added notes:breaking-changes Noted in Breaking Changes section api-change This PR should be mentioned in #api-updates channel on Discord labels Apr 23, 2024
@sholderbach

Copy link
Copy Markdown
Member

Inclined to get this in soon if there are no objections by others as this is a breaking change for plugin signatures and generally has the potential to cause some minor merge conflicts if this branch diverges for too long.

@IanManske
IanManske merged commit 9996e4a into nushell:main Apr 24, 2024
@IanManske

Copy link
Copy Markdown
Member Author

Ok merging, since it looks like there's no other objections 😅.

@hustcer hustcer added this to the v0.93.0 milestone Apr 25, 2024
@IanManske
IanManske deleted the shrink-expr branch May 27, 2024 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-change This PR should be mentioned in #api-updates channel on Discord notes:breaking-changes Noted in Breaking Changes section

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants