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

feat: port node:zlib to rust #18291

Merged
merged 22 commits into from
Mar 27, 2023
Merged

Conversation

littledivy
Copy link
Member

@littledivy littledivy commented Mar 20, 2023

Following a more simpler approach than #18176.

TODO:

  • op_zlib_new
  • op_zlib_close
  • op_zlib_write (and async)
  • op_zlib_init
  • op_zlib_params
  • op_zlib_reset

@bartlomieju bartlomieju self-requested a review March 21, 2023 14:04
@littledivy
Copy link
Member Author

# zlib port
        0.02 real         0.01 user         0.00 sys
            33685504  maximum resident set size
                2275  page reclaims
                  37  involuntary context switches
           183640103  instructions retired
            57041452  cycles elapsed
            14042560  peak memory footprint
# main
        0.04 real         0.02 user         0.01 sys
            34308096  maximum resident set size
                2311  page reclaims
                  37  involuntary context switches
           183867121  instructions retired
            55944666  cycles elapsed
            14304640  peak memory footprint

Some improvement in memory usage while there is no visible difference in startup time.

@bartlomieju
Copy link
Member

bartlomieju commented Mar 21, 2023

This PR:
Snapshot size: 4_769_424, took 43.374917ms

main branch
Snapshot size: 5_039_504, took 39.408541ms

So we got 270kB saved here. That's a huge improvement 👍

EDIT: Looking at flamegraphs I can see about 2 point reduction in time it takes to deserialize the snapshot and create a context (~59% -> ~57%)

@littledivy littledivy added the ci-bench put this on a PR to run the benchmarks label Mar 22, 2023
@littledivy littledivy marked this pull request as ready for review March 22, 2023 12:27
Copy link
Contributor

@mmastrac mmastrac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good so far.. some early comments.

ext/node/zlib/mod.rs Outdated Show resolved Hide resolved
ext/node/zlib/mod.rs Show resolved Hide resolved
ext/node/zlib/mod.rs Show resolved Hide resolved
ext/node/zlib/mod.rs Outdated Show resolved Hide resolved
ext/node/zlib/mod.rs Outdated Show resolved Hide resolved
ext/node/zlib/mod.rs Outdated Show resolved Hide resolved
ext/node/zlib/mod.rs Outdated Show resolved Hide resolved
ext/node/zlib/alloc.rs Show resolved Hide resolved
const GZIP_HEADER_ID2: u8 = 0x8b;

impl ZlibInner {
fn start_write(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize the zlib API is not terribly ergonomic, but bifurcating the compress/decompress paths into separate functions may simplify the code. I don't think this necessarily has to happen, but it would be much easier to understand if the code paths where separated in that way.

@littledivy
Copy link
Member Author

~1ms exec time improvement on Linux

Benchmark 1: deno_main run --reload cli/tests/testdata/run/002_hello.ts 
  Time (mean ± σ):      25.7 ms ±   0.8 ms    [User: 15.8 ms, System: 10.2 ms]
  Range (min … max):    24.2 ms …  28.2 ms    112 runs

Benchmark 1: target/release/deno run --reload cli/tests/testdata/run/002_hello.ts 
  Time (mean ± σ):      24.8 ms ±   1.2 ms    [User: 15.6 ms, System: 9.6 ms]
  Range (min … max):    22.9 ms …  33.3 ms    110 runs

@bartlomieju bartlomieju requested a review from mmastrac March 24, 2023 11:53
ext/node/zlib/mod.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@mmastrac mmastrac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one small nit

Co-authored-by: Matt Mastracci <[email protected]>
@littledivy littledivy enabled auto-merge (squash) March 27, 2023 15:50
@littledivy littledivy merged commit b2fd074 into denoland:main Mar 27, 2023
mmastrac pushed a commit that referenced this pull request Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci-bench put this on a PR to run the benchmarks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants