feat: allow custom priority for workers#377
Conversation
📝 WalkthroughWalkthroughThis PR introduces quality-of-service (QoS) parameter support for NativeScript worker threads. The Worker constructor now accepts an optional ChangesWorker Thread Quality of Service Support
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@NativeScript/runtime/Worker.mm`:
- Around line 114-120: The ios QoS mapping in the priority branch (checks for
"userInteractive", "userInitiated", "default", "utility") incorrectly hardcodes
hex literals; change those branches to use the NSQualityOfService constants
(e.g., NSQualityOfServiceUserInteractive, NSQualityOfServiceUserInitiated,
NSQualityOfServiceDefault/NSQualityOfServiceUtility) and modify the "default"
branch so it does not force an explicit QoS value (i.e., leave qos unset or set
to the sentinel used by worker->Start(..., qos) to indicate “do not set QoS”);
update the code around worker->Start(..., qos) to pass that sentinel when
priority == "default" and ensure all other branches use the named
NSQualityOfService* constants instead of hex literals.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 236f41b7-1842-487f-8583-141ad44b2b77
📒 Files selected for processing (3)
NativeScript/runtime/DataWrapper.hNativeScript/runtime/Worker.mmNativeScript/runtime/WorkerWrapper.mm
| if (priority == "userInteractive") { | ||
| qos = 0x21; // NSQualityOfServiceUserInteractive | ||
| } else if (priority == "userInitiated") { | ||
| qos = 0x19; // NSQualityOfServiceUserInitiated | ||
| } else if (priority == "default") { | ||
| qos = 0x15; // NSQualityOfServiceDefault | ||
| } else if (priority == "utility") { |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
What are the official raw values for the iOS NSQualityOfService enum, including NSQualityOfServiceDefault?
💡 Result:
I couldn’t find an authoritative Apple source that states the integer raw values (e.g., via a “raw value” table or enum definition) for the iOS NSQualityOfService enum cases, including NSQualityOfServiceDefault. What the official Apple docs do provide is the set of QoS levels (UserInteractive, UserInitiated, Utility, Background) and that “default” means “no explicit quality of service information / treated as default.” Apple’s Energy Efficiency Guide for iOS Apps states that when no QoS information is assigned, work is treated as default, and lists only the primary QoS constants (UserInteractive/UserInitiated/Utility/Background) as the developer-facing choices [1]. Apple’s Swift doc for the “QualityOfService.default” case also describes it as “Indicates no explicit quality of service information” and clarifies how the system picks an appropriate QoS when “default” is used (again, without giving a raw integer) [2]. So, while I can confirm the semantic meaning of “default,” I cannot (from the sources found) provide the exact official integer raw values for NSQualityOfService (including NSQualityOfServiceDefault).
Citations:
- 1: https://developer.apple.com/library/archive/documentation/Performance/Conceptual/EnergyGuide-iOS/PrioritizeWorkWithQoS.html
- 2: https://sosumi.ai/documentation/Foundation/QualityOfService/default
Fix QoS mapping for iosPriority: "default" in NativeScript/runtime/Worker.mm
Apple defines QoS “default” as “no explicit quality-of-service information” (system selects an appropriate QoS). The current mapping forces an explicit hardcoded value (qos = 0x15) for "default", which risks overriding the intended semantics. Replace the hardcoded hex QoS literals with NSQualityOfService* constants, and ensure "default" results in “do not set QoS” behavior (or the equivalent sentinel/path supported by the worker->Start(..., qos) contract).
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@NativeScript/runtime/Worker.mm` around lines 114 - 120, The ios QoS mapping
in the priority branch (checks for "userInteractive", "userInitiated",
"default", "utility") incorrectly hardcodes hex literals; change those branches
to use the NSQualityOfService constants (e.g.,
NSQualityOfServiceUserInteractive, NSQualityOfServiceUserInitiated,
NSQualityOfServiceDefault/NSQualityOfServiceUtility) and modify the "default"
branch so it does not force an explicit QoS value (i.e., leave qos unset or set
to the sentinel used by worker->Start(..., qos) to indicate “do not set QoS”);
update the code around worker->Start(..., qos) to pass that sentinel when
priority == "default" and ensure all other branches use the named
NSQualityOfService* constants instead of hex literals.
Summary by CodeRabbit
New Features
iosPriorityparameter, enabling fine-tuned thread priority management.Bug Fixes