nushell/crates
Devyn Cairns 1a5bf2447a
Use Arc for environment variables on the stack (#13333)
# Description

This is another easy performance lift that just changes `env_vars` and
`env_hidden` on `Stack` to use `Arc`. I noticed that these were being
cloned on essentially every closure invocation during captures
gathering, so we're paying the cost for all of that even when we don't
change anything. On top of that, for `env_vars`, there's actually an
entirely fresh `HashMap` created for each child scope, so it's highly
unlikely that we'll modify the parent ones.

Uses `Arc::make_mut` instead to take care of things when we need to
mutate something, and most of the time nothing has to be cloned at all.

# Benchmarks

The benefits are greater the more calls there are to env-cloning
functions like `captures_to_stack()`. Calling custom commands in a loop
is basically best case for a performance improvement. Plain `each` with
a literal block isn't so badly affected because the stack is set up
once.

## random_bytes.nu

```nushell
use std bench
do {
  const SCRIPT = ../nu_scripts/benchmarks/random-bytes.nu
  let before_change = bench { nu $SCRIPT }
  let after_change = bench { target/release/nu $SCRIPT }
  {
    before: ($before_change | reject times),
    after: ($after_change | reject times)
  }
}
```

```
╭────────┬──────────────────────────────╮
│        │ ╭──────┬───────────────────╮ │
│ before │ │ mean │ 603ms 759µs 727ns │ │
│        │ │ min  │ 593ms 298µs 167ns │ │
│        │ │ max  │ 648ms 612µs 291ns │ │
│        │ │ std  │ 9ms 335µs 251ns   │ │
│        │ ╰──────┴───────────────────╯ │
│        │ ╭──────┬───────────────────╮ │
│ after  │ │ mean │ 518ms 400µs 557ns │ │
│        │ │ min  │ 507ms 762µs 583ns │ │
│        │ │ max  │ 566ms 695µs 166ns │ │
│        │ │ std  │ 9ms 554µs 767ns   │ │
│        │ ╰──────┴───────────────────╯ │
╰────────┴──────────────────────────────╯
```

## gradient_benchmark_no_check.nu

```nushell
use std bench
do {
  const SCRIPT = ../nu_scripts/benchmarks/gradient_benchmark_no_check.nu
  let before_change = bench { nu $SCRIPT }
  let after_change = bench { target/release/nu $SCRIPT }
  {
    before: ($before_change | reject times),
    after: ($after_change | reject times)
  }
}
```

```
╭────────┬──────────────────────────────╮
│        │ ╭──────┬───────────────────╮ │
│ before │ │ mean │ 146ms 543µs 380ns │ │
│        │ │ min  │ 142ms 416µs 166ns │ │
│        │ │ max  │ 189ms 595µs       │ │
│        │ │ std  │ 7ms 140µs 342ns   │ │
│        │ ╰──────┴───────────────────╯ │
│        │ ╭──────┬───────────────────╮ │
│ after  │ │ mean │ 134ms 211µs 678ns │ │
│        │ │ min  │ 132ms 433µs 125ns │ │
│        │ │ max  │ 135ms 722µs 583ns │ │
│        │ │ std  │ 793µs 134ns       │ │
│        │ ╰──────┴───────────────────╯ │
╰────────┴──────────────────────────────╯
```

# User-Facing Changes
Better performance, particularly for custom commands, especially if
there are a lot of environment variables. Nothing else.

# Tests + Formatting
All passing.
2024-07-10 17:34:50 -07:00
..
nu_plugin_custom_values Bumping version to 0.95.1 (#13231) 2024-06-25 18:26:07 -07:00
nu_plugin_example Add and use new Signals struct (#13314) 2024-07-07 22:29:01 +00:00
nu_plugin_formats remove the deprecated register command (#13297) 2024-07-05 07:16:50 -05:00
nu_plugin_gstat remove the deprecated register command (#13297) 2024-07-05 07:16:50 -05:00
nu_plugin_inc remove the deprecated register command (#13297) 2024-07-05 07:16:50 -05:00
nu_plugin_nu_example Bumping version to 0.95.1 (#13231) 2024-06-25 18:26:07 -07:00
nu_plugin_polars Make polars unpivot consistent with polars pivot (#13335) 2024-07-10 16:36:38 -05:00
nu_plugin_python remove the deprecated register command (#13297) 2024-07-05 07:16:50 -05:00
nu_plugin_query remove the deprecated register command (#13297) 2024-07-05 07:16:50 -05:00
nu_plugin_stress_internals Bumping version to 0.95.1 (#13231) 2024-06-25 18:26:07 -07:00
nu-cli Internal representation (IR) compiler and evaluator (#13330) 2024-07-10 17:33:59 -07:00
nu-cmd-base Path migration 1 (#13309) 2024-07-09 17:25:23 +08:00
nu-cmd-extra Add and use new Signals struct (#13314) 2024-07-07 22:29:01 +00:00
nu-cmd-lang Internal representation (IR) compiler and evaluator (#13330) 2024-07-10 17:33:59 -07:00
nu-cmd-plugin remove the deprecated register command (#13297) 2024-07-05 07:16:50 -05:00
nu-color-config Bumping version to 0.95.1 (#13231) 2024-06-25 18:26:07 -07:00
nu-command Internal representation (IR) compiler and evaluator (#13330) 2024-07-10 17:33:59 -07:00
nu-derive-value Bumping version to 0.95.1 (#13231) 2024-06-25 18:26:07 -07:00
nu-engine Use Arc for environment variables on the stack (#13333) 2024-07-10 17:34:50 -07:00
nu-explore Add and use new Signals struct (#13314) 2024-07-07 22:29:01 +00:00
nu-glob Bumping version to 0.95.1 (#13231) 2024-06-25 18:26:07 -07:00
nu-json Bumping version to 0.95.1 (#13231) 2024-06-25 18:26:07 -07:00
nu-lsp Add and use new Signals struct (#13314) 2024-07-07 22:29:01 +00:00
nu-parser Internal representation (IR) compiler and evaluator (#13330) 2024-07-10 17:33:59 -07:00
nu-path Add typed path forms (#13115) 2024-06-25 18:33:57 -07:00
nu-plugin Add and use new Signals struct (#13314) 2024-07-07 22:29:01 +00:00
nu-plugin-core Add and use new Signals struct (#13314) 2024-07-07 22:29:01 +00:00
nu-plugin-engine Internal representation (IR) compiler and evaluator (#13330) 2024-07-10 17:33:59 -07:00
nu-plugin-protocol Internal representation (IR) compiler and evaluator (#13330) 2024-07-10 17:33:59 -07:00
nu-plugin-test-support Add and use new Signals struct (#13314) 2024-07-07 22:29:01 +00:00
nu-pretty-hex Bumping version to 0.95.1 (#13231) 2024-06-25 18:26:07 -07:00
nu-protocol Use Arc for environment variables on the stack (#13333) 2024-07-10 17:34:50 -07:00
nu-std don't show result in error make examples (#13296) 2024-07-05 07:17:07 -05:00
nu-system Bumping version to 0.95.1 (#13231) 2024-06-25 18:26:07 -07:00
nu-table update table comments 2024-07-09 19:52:57 -05:00
nu-term-grid Bumping version to 0.95.1 (#13231) 2024-06-25 18:26:07 -07:00
nu-test-support Internal representation (IR) compiler and evaluator (#13330) 2024-07-10 17:33:59 -07:00
nu-utils Add and use new Signals struct (#13314) 2024-07-07 22:29:01 +00:00
nuon Bumping version to 0.95.1 (#13231) 2024-06-25 18:26:07 -07:00
README.md Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00

Nushell core libraries and plugins

These sub-crates form both the foundation for Nu and a set of plugins which extend Nu with additional functionality.

Foundational libraries are split into two kinds of crates:

  • Core crates - those crates that work together to build the Nushell language engine
  • Support crates - a set of crates that support the engine with additional features like JSON support, ANSI support, and more.

Plugins are likewise also split into two types:

  • Core plugins - plugins that provide part of the default experience of Nu, including access to the system properties, processes, and web-connectivity features.
  • Extra plugins - these plugins run a wide range of different capabilities like working with different file types, charting, viewing binary data, and more.