Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

refactor(rome_cli): refactor the threading of parallel traversal to increase occupancy - #3577

Merged
leops merged 2 commits into
mainfrom
refactor/cli-threads
Nov 7, 2022
Merged

leops merged 2 commits into
mainfrom
refactor/cli-threads

Conversation

@leops

@leops leops commented Nov 7, 2022

Copy link
Copy Markdown
Contributor

Summary

This PR changes how threads are spawned during parallel traversal operations: it merges the console and report tasks into a single dedicated thread running outside of the Rayon thread pool, so that all threads in the pool are now available to process files.

I've also made the initial setup of input tasks run on the main thread (to avoid allocating an extraneous thread for this), and replaced some redundant cloning operations of the traversal state with shared references (this is made possible by using the scoped thread API of the standard library from Rust 1.63)

Test Plan

This is purely an internal change, it should have no noticeable side effect other than possibly improving traversal performance on multi-core systems, and the existing test suite of the CLI should ensure this is actually the case.

@leops
leops temporarily deployed to netlify-playground November 7, 2022 13:27 Inactive
@netlify

netlify Bot commented Nov 7, 2022 •

Copy link
Copy Markdown

✅ Deploy Preview for docs-rometools canceled.

Name Link
🔨 Latest commit 51fa409
🔍 Latest deploy log https://app.netlify.com/sites/docs-rometools/deploys/636917a1d75fb0000803a499

@leops

leops commented Nov 7, 2022

Copy link
Copy Markdown
Contributor Author

@MichaReiser Hopefully this should improve the wall time benchmarks a bit for the multi-threaded case

@github-actions

github-actions Bot commented Nov 7, 2022 •

Copy link
Copy Markdown

Comment thread crates/rome_cli/src/traversal.rs Resolved
duration = Some(traverse_inputs(
let duration = thread::scope(|s| {
thread::Builder::new()
.name(String::from("rome::console"))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice!

static INIT_ONCE: Once = Once::new();
INIT_ONCE.call_once(|| {
rayon::ThreadPoolBuilder::new()
.thread_name(|index| format!("rome::worker_{index}"))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you make sure to respect the RAYON_NUM_THREADS env variable? Or I have to find a new way to limit the threads in my benchmarks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Since the .num_threads() method is never called on the ThreadPoolBuilder it the size of the thread pool should be the default value of either the RAYON_NUM_THREADS variable or num_cpus

@leops
leops temporarily deployed to netlify-playground November 7, 2022 14:35 Inactive
@leops
leops merged commit b6af8f0 into main Nov 7, 2022
@leops
leops deleted the refactor/cli-threads branch November 7, 2022 16:25
jeysal added a commit to jeysal/rometools that referenced this pull request Nov 8, 2022
* upstream/main:
  fix(ci): fix the release workflows for the stable release (rome#3583)
  Fix logo container margin
  Fix mobile docs regressions
  perf: End-to-end Linter and Formatter benchmarks (rome#3570)
  doc: VS Code extension (rome#3579)
  refactor(rome_cli): refactor the threading of parallel traversal to increase occupancy (rome#3577)
  [docs] Add navigation dropdown for docs (rome#3578)
  doc(rome_cli): Document `--files-max-size` option
  perf(rome_js_semantic): Use FX Hash function (rome#3565)
  fix(rome_js_analyzer): `noInvalidConstructorSuper` false positive for class expressions (rome#3561)
  Clean up mobile navigation
  doc(website): Run `cargo lintdoc` (rome#3567)
  doc: Fix install command
  Fix mobile code blocks
  Fix dark mode logo
  Update links
  Implement new website (rome#3556)
@leops leops added the A-CLI Area: CLI label Nov 9, 2022

This branch was previously deployed

1 inactive deployment
netlify-playground — 51fa4096 Deployed Nov 7, 2022 by leops
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

A-CLI Area: CLI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants