Files
Darren Schroeder 3870f187e7 Speed up JSON, CSV, YAML and TOML conversion on big inputs (#19666)
## Description

This is the first easy stab at making formats a bit faster. There's
still lots of room for better perf.

Most of the time spent loading and saving big files went into copying
and converting data around the parsers, not into parsing. This PR
removes that work:

- `from json` parsed into a JSON value tree, with a hash map for every
object, and then converted the tree into nushell values. Before that it
copied the whole input once more. It now builds nushell values straight
from the parser, in both default and `--strict` mode. `to json` no
longer copies the value into a JSON tree before writing it.
- `to csv` and `to tsv` built a new CSV writer with an 8 KiB buffer for
every row and handed out one row per chunk, so `save` made one `write`
call per row. For a table that is already in memory, they now fill the
writer's buffer before handing out a chunk. String cells are borrowed
instead of copied.
- `from yaml` ran the int, float and timestamp regexes on every plain
scalar. Each of those patterns starts with a sign, a digit or a dot, so
scalars that start with anything else now skip them. Plain decimal ints
are read without the capture regex. A mapping without `<<` is no longer
merged into an empty record one key at a time. `to yaml` no longer
formats a tag string for values that have no tag.
- `from toml` moves strings and keys out of the parsed TOML instead of
cloning them.

Apart from the fixes below, the output is the same as on main. I
compared 293 cases against main, covering Hjson, duplicate keys, number
edge cases, BOMs, error messages, CSV errors after several chunks, YAML
1.1 and 1

### Before and after

The table has 500k rows and 10 columns of ints, floats, bools, strings
and nulls, which is 139 MB as JSON. Times are from an idle M-series Mac.
"Before" is main. Write times include loading the table from msgpack,
which takes about 0.55 s and 848 MB on both.

| command | before | after |
|---|---|---|
| `open fixture.json` | 1.50 s, 1456 MB | 1.19 s, 979 MB |
| `save fixture.json` | 1.81 s, 1760 MB | 1.00 s, 981 MB |
| `save fixture.csv` | 2.13 s | 1.05 s |
| `save fixture.tsv` | 2.13 s | 1.05 s |
| `open fixture.yaml` | 4.80 s | 3.27 s |
| `save fixture.yaml` | 1.50 s | 1.41 s |
| `open fixture.toml` | 2.20 s, 2902 MB | 2.07 s, 2799 MB |

## User-facing changes (Release notes)

- `from json` and `open` on `.json` files are faster and use a third
less memory on large inputs.
- `to json` and `save` to `.json` are about twice as fast on large
tables and use less memory.
- `to csv`, `to tsv` and `save` to `.csv` or `.tsv` are about twice as
fast on large tables.
- `from yaml` is about a third faster. `to yaml` and `from toml` are a
little faster.
- `from json` reports an error for a `/*` comment with no closing `*/`,
which used to crash nu.
- `from json` without `--strict` reports an error for lists and objects
nested more than 1024 deep, where deeper input used to crash nu with a
stack overflow. Input nested 1025 to about 11,000 levels deep parsed in
a release build before and now gets the error.
- `from yaml` reads -9223372036854775808, the smallest int.

## Additional notes
<!--
Optional.

Examples:
- fixes #123
- closes #456
- related #789

Anything else reviewers should know.
Remove this section if not needed.
-->
2026-11-25 13:12:07 -06:00
..
2026-08-02 03:52:40 +02:00
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.