Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse parsed modules #9125

Merged
merged 2 commits into from
May 7, 2023
Merged

Reuse parsed modules #9125

merged 2 commits into from
May 7, 2023

Conversation

kubouch
Copy link
Contributor

@kubouch kubouch commented May 7, 2023

Description

Similar to #8949, Nushell reuses parsed module if the same file is being parsed again.

Benchmarks

(results rounded to milliseconds, the mean values from bench vary within +-1 ms)

Baseline

Overhead of calling nu on empty file:

> touch empty.nu
> bench { nu empty.nu } | get mean
~40ms
> bench { /home/kubouch/.cargo/target/release/nu empty.nu } | get mean
~40ms

Benchmark 1

Repeated calls to use

# test.nu
use crates/nu-std/lib/mod.nu
use crates/nu-std/lib/mod.nu
use crates/nu-std/lib/mod.nu
use crates/nu-std/lib/mod.nu
use crates/nu-std/lib/mod.nu
use crates/nu-std/lib/mod.nu
use crates/nu-std/lib/mod.nu
use crates/nu-std/lib/mod.nu
use crates/nu-std/lib/mod.nu
use crates/nu-std/lib/mod.nu
use crates/nu-std/lib/mod.nu
use crates/nu-std/lib/mod.nu
use crates/nu-std/lib/mod.nu
use crates/nu-std/lib/mod.nu
use crates/nu-std/lib/mod.nu
use crates/nu-std/lib/mod.nu

Old vs. new running times:

> use std bench
> bench { nu test.nu } | get main  
~128ms (+88 ms from baseline)
> bench { /home/kubouch/.cargo/target/release/nu test.nu } | get mean
~47ms (+7 ms from baseline)

Benchmark 2

Real project which reuses a utils module in several files (https://github.com/kubouch/nuun, commit 5bf92d799d1561ddebd329c3e8106d575f4c8fa0)

# test_nuun.nu
use /home/kubouch/git/nuun/nuun/
> use std bench
> bench { nu test_nuun.nu } | get main  
~48 ms (+8 ms from baseline)
> bench { /home/kubouch/.cargo/target/release/nu test_nuun.nu } | get mean
~46 ms (+6 ms from baseline)

User-Facing Changes

Speedup if parsing the same file more than once as a module.

Tests + Formatting

After Submitting

@codecov
Copy link

codecov bot commented May 7, 2023

Codecov Report

Merging #9125 (ad19e24) into main (0ea973b) will increase coverage by 0.00%.
The diff coverage is 96.66%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #9125   +/-   ##
=======================================
  Coverage   68.79%   68.80%           
=======================================
  Files         641      641           
  Lines      102104   102122   +18     
=======================================
+ Hits        70243    70264   +21     
+ Misses      31861    31858    -3     
Impacted Files Coverage Δ
crates/nu-parser/src/parse_keywords.rs 77.75% <92.30%> (+0.05%) ⬆️
crates/nu-protocol/src/engine/engine_state.rs 86.51% <100.00%> (+0.12%) ⬆️

... and 1 file with indirect coverage changes

@kubouch kubouch marked this pull request as ready for review May 7, 2023 11:35
@kubouch kubouch merged commit 2500719 into nushell:main May 7, 2023
@kubouch kubouch deleted the file-cache branch May 7, 2023 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant