Leaving presentation mode.
TPAC Breakout:
Web Worker
Quality of Service
Rijubrata Bhaumik, Zhibo Wang [Intel]
★ W3C TPAC 2023, Seville, 13 September ★
Web Workers
- Offload work from the main thread
- Ensure UI's responsiveness and smoothness
- Allows for laborious processing
- Audio/video processing in real-time communication
- Compressing or data processing
- Enables multi-threading
Workloads characteristics
-
Latency sensitive
Some tasks need to be run with best performance to minimize latency
-
Background tasks
Can be scheduled at low performance to get power efficiency
-
Expect to be prioritized
Audio glitches may happen if it is blocked by rendering
Windows
SetThreadPriority()
SetThreadInformation()
(ThreadPowerThrottling verion)
MacOS
pthread_attr_set_qos_class_np(3)
_np = non-portable
QoS Class
- User-interactive
- User-initiated
- Utility
- Background
Apple's
qos.h
Linux and ChromeOS
- Per thread EPP (Energy performance preference)
- Task placement decisions
- Preemption
- Energy Aware Scheduler
- Coming Soon 2024
sched_setattr(2)
- QOS_MEDIA
- QOS_INTERACTIVE
- QOS_DEFAULT
- QOS_UTILITY
- QOS_BACKGROUND
API
Example code
Make the worker run with efficiency
let worker = new Worker('worker.js',
{ qualityOfService: 'low' });
Make the worker run with performance
let worker = new Worker('worker.js',
{ qualityOfService: 'high' });
Power & perf. analysis (1/2)
Video conference with background blur
21% power saving, without losing FPS and delay
Power
Baseline |
100% |
qualityOfService: 'low' |
79% |
FPS
Baseline |
100% |
qualityOfService: 'low' |
100% |
Power & perf. analysis (2/2)
Squoosh.app webp image encoding
10% power saving, 2.7x execution time (37% FPS)
Power
Baseline |
100% |
qualityOfService: 'low' |
90% |
FPS
Baseline |
100% |
qualityOfService: 'low' |
37% |
Choice
- Is the qualityOfService modifiable after construction?
- Do we need a getter, setter, and an onchange event?
- Other names for attribute or enum values?
- Any permission issue if we allow user-defined thread priority?
Considered Alternatives
Worklets
are for limited specific purpose(audio, CSS painting), controlled by browser
HTML Priority Hints
are for resource fetching priorities
Conclusion
-
We propose a web worker quality of service, enabling js script run with
performance / efficiency / priority, to achieve better runtime
performance or power efficiency supported by modern processors.
- The API design and whether we should involve priority is still controversial.
- Questions?