Skip to content

script: implement navigator.hardwareConcurrency #31268

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

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

syvb
Copy link
Contributor

@syvb syvb commented Feb 5, 2024

Implements navigator.hardwareConcurrency, which returns the number of logical processors available.

I used the num_cpus library (which is already used by Servo in other places), and cache the result since it can be slow to query that information on some operating systems.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • There are tests for these changes

@@ -75,6 +75,7 @@ mime = { workspace = true }
mime_guess = { workspace = true }
msg = { workspace = true }
net_traits = { workspace = true }
num_cpus = "1.1.0"
Copy link
Member

Choose a reason for hiding this comment

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

Maybe is good to create an issue and link this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean I should create an issue in num_cpus? I don't see why this PR would warrant creating an issue.

Copy link
Member

Choose a reason for hiding this comment

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

no I meant on this repo

Copy link
Member

@mrobinson mrobinson left a comment

Choose a reason for hiding this comment

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

Nice! Just a few comments.

@@ -24,6 +27,13 @@ use crate::dom::window::Window;
use crate::dom::xrsystem::XRSystem;
use crate::script_runtime::JSContext;

pub(super) fn hardware_concurrency() -> u64 {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this function public? Could it simply be moved into the body of HardwareConcurrency(&self)? Since the code is not repeated, I'm not sure an extra function buys us much unless I'm misunderstanding.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's also called in components/script/dom/workernavigator.rs - I split it out to another function to avoid duplicating the logic in the Navigator and WorkerNavigator.

Signed-off-by: syvb <me@iter.ca>
@syvb syvb force-pushed the hardware-concurrency branch from 01f96a8 to 382cf13 Compare February 7, 2024 13:11
@mrobinson mrobinson added this pull request to the merge queue Feb 7, 2024
Merged via the queue into servo:main with commit 20404a7 Feb 7, 2024
@syvb syvb deleted the hardware-concurrency branch February 7, 2024 20:48
Taym95 pushed a commit to Taym95/servo that referenced this pull request Feb 11, 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