forked from extern/nushell
Shrink the size of Expr
(#12610)
# 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. `Expr`s and `Expression`s 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). --------- Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
This commit is contained in:
@@ -21,7 +21,7 @@ impl Command for DetectColumns {
|
||||
"number of rows to skip before detecting",
|
||||
Some('s'),
|
||||
)
|
||||
.input_output_types(vec![(Type::String, Type::Table(vec![]))])
|
||||
.input_output_types(vec![(Type::String, Type::table())])
|
||||
.switch("no-headers", "don't detect headers", Some('n'))
|
||||
.named(
|
||||
"combine-columns",
|
||||
|
@@ -17,8 +17,8 @@ impl Command for DecodeBase64 {
|
||||
Type::List(Box::new(Type::String)),
|
||||
Type::List(Box::new(Type::Any)),
|
||||
),
|
||||
(Type::Table(vec![]), Type::Table(vec![])),
|
||||
(Type::Record(vec![]), Type::Record(vec![])),
|
||||
(Type::table(), Type::table()),
|
||||
(Type::record(), Type::record()),
|
||||
])
|
||||
.allow_variants_without_examples(true)
|
||||
.named(
|
||||
|
@@ -28,8 +28,8 @@ impl Command for EncodeBase64 {
|
||||
Type::List(Box::new(Type::Any)),
|
||||
Type::List(Box::new(Type::String)),
|
||||
),
|
||||
(Type::Table(vec![]), Type::Table(vec![])),
|
||||
(Type::Record(vec![]), Type::Record(vec![])),
|
||||
(Type::table(), Type::table()),
|
||||
(Type::record(), Type::record()),
|
||||
])
|
||||
.allow_variants_without_examples(true)
|
||||
.named(
|
||||
|
@@ -18,7 +18,7 @@ impl Command for FormatDate {
|
||||
.input_output_types(vec![
|
||||
(Type::Date, Type::String),
|
||||
(Type::String, Type::String),
|
||||
(Type::Nothing, Type::Table(vec![])),
|
||||
(Type::Nothing, Type::table()),
|
||||
])
|
||||
.allow_variants_without_examples(true) // https://github.com/nushell/nushell/issues/7032
|
||||
.switch("list", "lists strftime cheatsheet", Some('l'))
|
||||
|
@@ -29,7 +29,7 @@ impl Command for FormatDuration {
|
||||
Type::List(Box::new(Type::Duration)),
|
||||
Type::List(Box::new(Type::String)),
|
||||
),
|
||||
(Type::Table(vec![]), Type::Table(vec![])),
|
||||
(Type::table(), Type::table()),
|
||||
])
|
||||
.allow_variants_without_examples(true)
|
||||
.required(
|
||||
|
@@ -25,8 +25,8 @@ impl Command for FormatFilesize {
|
||||
Signature::build("format filesize")
|
||||
.input_output_types(vec![
|
||||
(Type::Filesize, Type::String),
|
||||
(Type::Table(vec![]), Type::Table(vec![])),
|
||||
(Type::Record(vec![]), Type::Record(vec![])),
|
||||
(Type::table(), Type::table()),
|
||||
(Type::record(), Type::record()),
|
||||
])
|
||||
.allow_variants_without_examples(true)
|
||||
.required(
|
||||
|
@@ -26,8 +26,8 @@ impl Command for Parse {
|
||||
Signature::build("parse")
|
||||
.required("pattern", SyntaxShape::String, "The pattern to match.")
|
||||
.input_output_types(vec![
|
||||
(Type::String, Type::Table(vec![])),
|
||||
(Type::List(Box::new(Type::Any)), Type::Table(vec![])),
|
||||
(Type::String, Type::table()),
|
||||
(Type::List(Box::new(Type::Any)), Type::table()),
|
||||
])
|
||||
.switch("regex", "use full regex syntax for patterns", Some('r'))
|
||||
.allow_variants_without_examples(true)
|
||||
|
@@ -13,11 +13,11 @@ impl Command for SubCommand {
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("split column")
|
||||
.input_output_types(vec![
|
||||
(Type::String, Type::Table(vec![])),
|
||||
(Type::String, Type::table()),
|
||||
(
|
||||
// TODO: no test coverage (is this behavior a bug or a feature?)
|
||||
Type::List(Box::new(Type::String)),
|
||||
Type::Table(vec![]),
|
||||
Type::table(),
|
||||
),
|
||||
])
|
||||
.required(
|
||||
|
@@ -16,8 +16,8 @@ impl Command for SubCommand {
|
||||
Type::List(Box::new(Type::String)),
|
||||
Type::List(Box::new(Type::String)),
|
||||
),
|
||||
(Type::Table(vec![]), Type::Table(vec![])),
|
||||
(Type::Record(vec![]), Type::Record(vec![])),
|
||||
(Type::table(), Type::table()),
|
||||
(Type::record(), Type::record()),
|
||||
])
|
||||
.allow_variants_without_examples(true)
|
||||
.rest(
|
||||
|
@@ -16,8 +16,8 @@ impl Command for SubCommand {
|
||||
Type::List(Box::new(Type::String)),
|
||||
Type::List(Box::new(Type::String)),
|
||||
),
|
||||
(Type::Table(vec![]), Type::Table(vec![])),
|
||||
(Type::Record(vec![]), Type::Record(vec![])),
|
||||
(Type::table(), Type::table()),
|
||||
(Type::record(), Type::record()),
|
||||
])
|
||||
.allow_variants_without_examples(true)
|
||||
.rest(
|
||||
|
@@ -16,8 +16,8 @@ impl Command for SubCommand {
|
||||
Type::List(Box::new(Type::String)),
|
||||
Type::List(Box::new(Type::String)),
|
||||
),
|
||||
(Type::Table(vec![]), Type::Table(vec![])),
|
||||
(Type::Record(vec![]), Type::Record(vec![])),
|
||||
(Type::table(), Type::table()),
|
||||
(Type::record(), Type::record()),
|
||||
])
|
||||
.allow_variants_without_examples(true)
|
||||
.rest(
|
||||
|
@@ -29,8 +29,8 @@ impl Command for SubCommand {
|
||||
.input_output_types(vec![
|
||||
(Type::String, Type::Bool),
|
||||
// TODO figure out cell-path type behavior
|
||||
(Type::Table(vec![]), Type::Table(vec![])),
|
||||
(Type::Record(vec![]), Type::Record(vec![])),
|
||||
(Type::table(), Type::table()),
|
||||
(Type::record(), Type::record()),
|
||||
(Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Bool)))
|
||||
])
|
||||
.required("string", SyntaxShape::String, "The substring to find.")
|
||||
|
@@ -25,8 +25,8 @@ impl Command for SubCommand {
|
||||
Signature::build("str distance")
|
||||
.input_output_types(vec![
|
||||
(Type::String, Type::Int),
|
||||
(Type::Table(vec![]), Type::Table(vec![])),
|
||||
(Type::Record(vec![]), Type::Record(vec![])),
|
||||
(Type::table(), Type::table()),
|
||||
(Type::record(), Type::record()),
|
||||
])
|
||||
.required(
|
||||
"compare-string",
|
||||
|
@@ -28,8 +28,8 @@ impl Command for SubCommand {
|
||||
.input_output_types(vec![
|
||||
(Type::String, Type::Bool),
|
||||
(Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Bool))),
|
||||
(Type::Table(vec![]), Type::Table(vec![])),
|
||||
(Type::Record(vec![]), Type::Record(vec![])),
|
||||
(Type::table(), Type::table()),
|
||||
(Type::record(), Type::record()),
|
||||
])
|
||||
.allow_variants_without_examples(true)
|
||||
.required("string", SyntaxShape::String, "The string to match.")
|
||||
|
@@ -34,8 +34,8 @@ impl Command for SubCommand {
|
||||
.input_output_types(vec![
|
||||
(Type::String, Type::Int),
|
||||
(Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Int))),
|
||||
(Type::Table(vec![]), Type::Table(vec![])),
|
||||
(Type::Record(vec![]), Type::Record(vec![])),
|
||||
(Type::table(), Type::table()),
|
||||
(Type::record(), Type::record()),
|
||||
])
|
||||
.allow_variants_without_examples(true)
|
||||
.required("string", SyntaxShape::String, "The string to find in the input.")
|
||||
|
@@ -28,8 +28,8 @@ impl Command for SubCommand {
|
||||
.input_output_types(vec![
|
||||
(Type::String, Type::Int),
|
||||
(Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Int))),
|
||||
(Type::Table(vec![]), Type::Table(vec![])),
|
||||
(Type::Record(vec![]), Type::Record(vec![])),
|
||||
(Type::table(), Type::table()),
|
||||
(Type::record(), Type::record()),
|
||||
])
|
||||
.allow_variants_without_examples(true)
|
||||
.switch(
|
||||
|
@@ -31,8 +31,8 @@ impl Command for SubCommand {
|
||||
.input_output_types(vec![
|
||||
(Type::String, Type::String),
|
||||
// TODO: clarify behavior with cell-path-rest argument
|
||||
(Type::Table(vec![]), Type::Table(vec![])),
|
||||
(Type::Record(vec![]), Type::Record(vec![])),
|
||||
(Type::table(), Type::table()),
|
||||
(Type::record(), Type::record()),
|
||||
(
|
||||
Type::List(Box::new(Type::String)),
|
||||
Type::List(Box::new(Type::String)),
|
||||
|
@@ -17,8 +17,8 @@ impl Command for SubCommand {
|
||||
Type::List(Box::new(Type::String)),
|
||||
Type::List(Box::new(Type::String)),
|
||||
),
|
||||
(Type::Table(vec![]), Type::Table(vec![])),
|
||||
(Type::Record(vec![]), Type::Record(vec![])),
|
||||
(Type::table(), Type::table()),
|
||||
(Type::record(), Type::record()),
|
||||
])
|
||||
.allow_variants_without_examples(true)
|
||||
.rest(
|
||||
|
@@ -29,8 +29,8 @@ impl Command for SubCommand {
|
||||
.input_output_types(vec![
|
||||
(Type::String, Type::Bool),
|
||||
(Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Bool))),
|
||||
(Type::Table(vec![]), Type::Table(vec![])),
|
||||
(Type::Record(vec![]), Type::Record(vec![])),
|
||||
(Type::table(), Type::table()),
|
||||
(Type::record(), Type::record()),
|
||||
])
|
||||
.allow_variants_without_examples(true)
|
||||
.required("string", SyntaxShape::String, "The string to match.")
|
||||
|
@@ -18,7 +18,7 @@ impl Command for SubCommand {
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("str stats")
|
||||
.category(Category::Strings)
|
||||
.input_output_types(vec![(Type::String, Type::Record(vec![]))])
|
||||
.input_output_types(vec![(Type::String, Type::record())])
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
|
@@ -42,8 +42,8 @@ impl Command for SubCommand {
|
||||
.input_output_types(vec![
|
||||
(Type::String, Type::String),
|
||||
(Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String))),
|
||||
(Type::Table(vec![]), Type::Table(vec![])),
|
||||
(Type::Record(vec![]), Type::Record(vec![])),
|
||||
(Type::table(), Type::table()),
|
||||
(Type::record(), Type::record()),
|
||||
])
|
||||
.allow_variants_without_examples(true)
|
||||
.switch(
|
||||
|
@@ -36,8 +36,8 @@ impl Command for SubCommand {
|
||||
Type::List(Box::new(Type::String)),
|
||||
Type::List(Box::new(Type::String)),
|
||||
),
|
||||
(Type::Table(vec![]), Type::Table(vec![])),
|
||||
(Type::Record(vec![]), Type::Record(vec![])),
|
||||
(Type::table(), Type::table()),
|
||||
(Type::record(), Type::record()),
|
||||
])
|
||||
.allow_variants_without_examples(true)
|
||||
.rest(
|
||||
|
Reference in New Issue
Block a user