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

perf(compile): read embedded files as static references when UTF-8 and reading as strings #27033

Merged

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented Nov 23, 2024

Speed

let count = 0;
for (var i = 0; i < 500; i++) {
  const text = Deno.readTextFileSync(import.meta.dirname + "/test.txt");
  count += text.length;
}

console.log(count);
% hyperfine --warmup=4 './old' './new'
Benchmark 1: ./old
  Time (mean ± σ):      2.236 s ±  0.009 s    [User: 2.164 s, System: 0.423 s]
  Range (min … max):    2.224 s …  2.250 s    10 runs
 
Benchmark 2: ./new
  Time (mean ± σ):      1.570 s ±  0.003 s    [User: 1.552 s, System: 0.013 s]
  Range (min … max):    1.566 s …  1.574 s    10 runs
 
Summary
  ./new ran
    1.42 ± 0.01 times faster than ./old

I also checked perf of just reading a file from the file system and it is the same as before (expected... just was making sure that didn't regress somehow)

Memory Usage

import process from "node:process";

const data = [];
setInterval(() => {
  const text = Deno.readTextFileSync(import.meta.dirname + "/test.txt");
  data.push(text);
  console.log(process.memoryUsage().rss);
}, 1000);
scratch2 % ./old     
54738944
61014016
73236480
85245952
97648640
109740032
122765312
^C
scratch2 % ./new     
43417600
43548672
43859968
43876352
43876352
44154880
44171264
^C

ext/fs/ops.rs Show resolved Hide resolved
@dsherret dsherret force-pushed the perf_compile_read_files_static_references branch from da7f3bc to 681db9a Compare November 25, 2024 14:53
@dsherret dsherret changed the title perf(compile): read embedded files as static references perf(compile): read embedded files as static references when UTF-8 and reading as strings Nov 27, 2024
@dsherret dsherret marked this pull request as ready for review November 27, 2024 15:44
@dsherret dsherret requested a review from bartlomieju November 27, 2024 16:43
Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +25 to +26
// todo(https://github.com/denoland/deno_config/pull/140): avoid clone
.map(|s| s.into_owned())
Copy link
Member

Choose a reason for hiding this comment

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

I guess this can be addressed now since it was landed in denoland/deno_config#141. I can take care of that in my PR.

Comment on lines +879 to +880
// todo(https://github.com/denoland/deno_package_json/pull/9): don't clone
.map(|text| text.into_owned())
Copy link
Member

Choose a reason for hiding this comment

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

This can addressed in #27096

@@ -887,6 +892,8 @@ impl<'a> deno_package_json::fs::DenoPkgJsonFs for DenoPkgJsonFsAdapter<'a> {
self
.0
.read_text_file_lossy_sync(path, None)
// todo(https://github.com/denoland/deno_package_json/pull/9): don't clone
.map(|text| text.into_owned())
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

@dsherret dsherret merged commit f161adf into denoland:main Nov 28, 2024
17 checks passed
@dsherret dsherret deleted the perf_compile_read_files_static_references branch November 28, 2024 02:28
bartlomieju pushed a commit that referenced this pull request Nov 28, 2024
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.

3 participants