feat: dispatch warning event on timer saturation#569
Closed
jerome-benoit wants to merge 1 commit into
Closed
Conversation
Add a 'warning' event to BenchEvents and TaskEvents that is dispatched on both the Bench and the Task instances when the latency samples of a task are dominated by the timer resolution. Saturation is detected by a new internal detectTimerSaturation helper in src/utils.ts. It reports true on any of: - more than half of the samples are zero - the number of distinct sample values is below max(3, min(10, n / 1000)) - the median absolute deviation is zero with more than 100 samples The event is purely informative and has no listener by default, so the change is runtime-compatible. It only widens the BenchEvents string union, which is a soft compile-time signal for users who exhaustively switch on event types.
commit: |
This was referenced May 30, 2026
Collaborator
Author
|
Closed in favor of #571 which consolidates this feature with #568 and #570. The audit found that the saturation detection in this PR must operate on the raw latency samples and the raw MAD; running it after the in-place overhead correction from #568 inflates |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a
'warning'event toBenchEventsandTaskEventsthat is dispatched on both theBenchand theTaskinstances when the latency samples of a task are dominated by the timer resolution.Implementation
Saturation is detected by a new internal
detectTimerSaturation(samples, mad)helper insrc/utils.ts. It returnstrueon any of:max(3, min(10, n / 1000))The event is dispatched in
Task#processRunResultright afterthis.#resultis set with a'completed'or'aborted-with-statistics'state, before the'cycle'event so thatcyclelisteners can observe the warning state if they need to.Risk
Runtime-compatible — the event is purely informative and has no listener by default. The only observable change is widening the
BenchEventsstring union with'warning', which is a soft compile-time signal for users who exhaustivelyswitchon event types and treat unknown variants as errors. No bump beyondfeat:is warranted because no existing API contract is removed or changed in shape.