nushell/crates
Reilly Wood 3b5172a8fa
LazyRecord (#7619)
This is an attempt to implement a new `Value::LazyRecord` variant for
performance reasons.

`LazyRecord` is like a regular `Record`, but it's possible to access
individual columns without evaluating other columns. I've implemented
`LazyRecord` for the special `$nu` variable; accessing `$nu` is
relatively slow because of all the information in `scope`, and [`$nu`
accounts for about 2/3 of Nu's startup time on
Linux](https://github.com/nushell/nushell/issues/6677#issuecomment-1364618122).

### Benchmarks

I ran some benchmarks on my desktop (Linux, 12900K) and the results are
very pleasing.

Nu's time to start up and run a command (`cargo build --release;
hyperfine 'target/release/nu -c "echo \"Hello, world!\""' --shell=none
--warmup 10`) goes from **8.8ms to 3.2ms, about 2.8x faster**.

Tests are also much faster! Running `cargo nextest` (with our very slow
`proptest` tests disabled) goes from **7.2s to 4.4s (1.6x faster)**,
because most tests involve launching a new instance of Nu.

### Design (updated)

I've added a new `LazyRecord` trait and added a `Value` variant wrapping
those trait objects, much like `CustomValue`. `LazyRecord`
implementations must implement these 2 functions:

```rust
// All column names
fn column_names(&self) -> Vec<&'static str>;

// Get 1 specific column value
fn get_column_value(&self, column: &str) -> Result<Value, ShellError>;
 ```

### Serializability

`Value` variants must implement `Serializable` and `Deserializable`, which poses some problems because I want to use unserializable things like `EngineState` in `LazyRecord`s. To work around this, I basically lie to the type system:

1. Add `#[typetag::serde(tag = "type")]` to `LazyRecord` to make it serializable
2. Any unserializable fields in `LazyRecord` implementations get marked with `#[serde(skip)]`
3. At the point where a `LazyRecord` normally would get serialized and sent to a plugin, I instead collect it into a regular `Value::Record` (which can be serialized)
2023-01-18 19:27:26 -08:00
..
nu-cli LazyRecord (#7619) 2023-01-18 19:27:26 -08:00
nu-color-config Bump to 0.74.1 development version (#7721) 2023-01-11 22:30:41 +01:00
nu-command LazyRecord (#7619) 2023-01-18 19:27:26 -08:00
nu-engine LazyRecord (#7619) 2023-01-18 19:27:26 -08:00
nu-explore fix some typos (#7773) 2023-01-16 12:43:46 +01:00
nu-glob Fix typos and use more idiomatic assertions (#7755) 2023-01-15 15:03:32 +13:00
nu-json Bump to 0.74.1 development version (#7721) 2023-01-11 22:30:41 +01:00
nu-parser fix some typos (#7773) 2023-01-16 12:43:46 +01:00
nu-path Fix typos and use more idiomatic assertions (#7755) 2023-01-15 15:03:32 +13:00
nu-plugin LazyRecord (#7619) 2023-01-18 19:27:26 -08:00
nu-pretty-hex Fix typos and use more idiomatic assertions (#7755) 2023-01-15 15:03:32 +13:00
nu-protocol LazyRecord (#7619) 2023-01-18 19:27:26 -08:00
nu-system Bump once_cell from 1.16.0 to 1.17.0 (#7732) 2023-01-11 23:00:44 +00:00
nu-table fix some typos (#7773) 2023-01-16 12:43:46 +01:00
nu-term-grid Bump to 0.74.1 development version (#7721) 2023-01-11 22:30:41 +01:00
nu-test-support Bump to 0.74.1 development version (#7721) 2023-01-11 22:30:41 +01:00
nu-utils Add cursor shape configuration for each edit mode (#7745) 2023-01-13 14:37:39 -06:00
nu_plugin_custom_values Bump to 0.74.1 development version (#7721) 2023-01-11 22:30:41 +01:00
nu_plugin_example Bump to 0.74.1 development version (#7721) 2023-01-11 22:30:41 +01:00
nu_plugin_gstat Bump git2 from 0.15.0 to 0.16.0 (#7731) 2023-01-11 22:56:02 +00:00
nu_plugin_inc update semver dep (#7771) 2023-01-15 20:39:27 -06:00
nu_plugin_python Fix typos by codespell (#7600) 2022-12-26 02:31:26 -05:00
nu_plugin_query fix some typos (#7773) 2023-01-16 12:43:46 +01: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.