Commit Graph
340 Commits
Author SHA1 Message Date
Damien Carver 674f818526 Bug 2040410 - Migrate TimerMarker and AddRemoveTimerMarker. r=canova
Use StreamPayloadHelper<TimeDuration> for the duration fields in
TimerMarker and AddRemoveTimerMarker.

Differential Revision: https://phabricator.services.mozilla.com/D301279
2026-06-03 13:03:55 +00:00
Alexandru Marc 654a9d2281 Revert "Bug 2040410: apply code formatting via Lando" for causing SM bustages @ BaseProfilerMarkersPrerequisites
This reverts commit 8ca646d720.

Revert "Bug 2040410 - Migrate TimerMarker and AddRemoveTimerMarker. r=canova"

This reverts commit 105b050a1e.

Revert "Bug 2040410 - Add unittest for StreamPayloadHelper<TimeDuration>. r=canova"

This reverts commit dac9adb6fc.

Revert "Bug 2040410 - Add StreamPayloadHelper<TimeDuration>. r=canova,profiler-reviewers"

This reverts commit 86137747bf.
2026-06-02 11:20:46 +00:00
Damien Carver 105b050a1e Bug 2040410 - Migrate TimerMarker and AddRemoveTimerMarker. r=canova
Use StreamPayloadHelper<TimeDuration> for the duration fields in
TimerMarker and AddRemoveTimerMarker.

Differential Revision: https://phabricator.services.mozilla.com/D301279
2026-06-02 10:55:47 +00:00
Daniel Holbert ac764635e4 Bug 2043772: Use MakeRefPtr to do allocation for various RefPtr variables in xpcom/threads/. r=xpcom-reviewers,emilio
Differential Revision: https://phabricator.services.mozilla.com/D303524
2026-05-30 14:29:48 +00:00
serge-sans-paille 60cafad33c Bug 2025926 - Remove unused <cmath> inclusion and make sure we don't regress on those r=emilio,media-playback-reviewers,webrtc-reviewers,win-reviewers,firefox-style-system-reviewers,dshin,mjf,gstoll,padenot
Leveraging the `mach lint -lincludes` infrastructure

Differential Revision: https://phabricator.services.mozilla.com/D289623
2026-03-26 12:30:41 +00:00
serge-sans-paille f81328e365 Bug 2023519 - Make our codebase modernize-use-equals-default + modernize-use-equals-delete -safe wrt. clang-tidy r=sylvestre,necko-reviewers,media-playback-reviewers,profiler-reviewers,dom-storage-reviewers,layout-reviewers,dom-worker-reviewers,valentin,jesup,padenot,edenchuang,emilio
The changeset has been generated automatically through:

    ./mach static-analysis check --output ./clang-tidy-bugprone.json --format json --fix

followed by manual adjustment when needed or when the auto-fixer bailed out.

This paves the way for Bug 2023527

Differential Revision: https://phabricator.services.mozilla.com/D287941
2026-03-22 08:35:47 +00:00
Alexandru Marc 04e5f74151 Revert "Bug 2023519 - Make our codebase modernize-use-equals-default + modernize-use-equals-delete -safe wrt. clang-tidy r=sylvestre,necko-reviewers,media-playback-reviewers,profiler-reviewers,dom-storage-reviewers,layout-reviewers,dom-worker-reviewers,valentin,jesup,padenot,edenchuang,emilio"
This reverts commit a64dec2665.
2026-03-19 17:29:58 +00:00
serge-sans-paille a64dec2665 Bug 2023519 - Make our codebase modernize-use-equals-default + modernize-use-equals-delete -safe wrt. clang-tidy r=sylvestre,necko-reviewers,media-playback-reviewers,profiler-reviewers,dom-storage-reviewers,layout-reviewers,dom-worker-reviewers,valentin,jesup,padenot,edenchuang,emilio
The changeset has been generated automatically through:

    ./mach static-analysis check --output ./clang-tidy-bugprone.json --format json --fix

followed by manual adjustment when needed or when the auto-fixer bailed out.

This paves the way for Bug 2023527

Differential Revision: https://phabricator.services.mozilla.com/D287941
2026-03-18 17:25:01 +00:00
Sylvestre Ledru 6149f49299 Bug 2023419 - Remove Emacs/Vim modelines from xpcom/ r=emilio
replaced by .editorconfig
# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D287878
2026-03-16 17:22:07 +00:00
André Bargull 22f5b5c7c5 Bug 2020608 - Part 12: Replace IsPowerOfTwo with std::has_single_bit outside of js/. r=sergesanspaille,profiler-reviewers,win-reviewers,gstoll,canaltinova
`mozilla::IsPowerOfTwo` is used in more code than the previous functions, so split
up the updates in three parts. This part updates non-SpiderMonkey code to use
`std::has_single_bit`. The next part updates SpiderMonkey code and the last part
finally removes `mozilla::IsPowerOfTwo`.

Differential Revision: https://phabricator.services.mozilla.com/D286320
2026-03-14 14:08:50 +00:00
Atila Butkovits 3578df2975 Revert "Bug 2020608 - Part 17: Use std::rot[lr] for Rotate(Left|Right). r=sergesanspaille" for causing bustages at PowerOfTwo.h.
This reverts commit eb884a9f65.

Revert "Bug 2020608 - Part 16: Use std::bit_ceil for RoundUpPow2. r=sergesanspaille"

This reverts commit 35a310aa8a.

Revert "Bug 2020608 - Part 15: Require unsigned integral types for CeilingLog2 and FindMostSignificantBit. r=sergesanspaille,nbp"

This reverts commit f682901ca2.

Revert "Bug 2020608 - Part 14: Remove mozilla::IsPowerOfTwo. r=sergesanspaille"

This reverts commit b998e4bd39.

Revert "Bug 2020608 - Part 13: Replace IsPowerOfTwo with std::has_single_bit in js/. r=sergesanspaille"

This reverts commit 00db5e1f32.

Revert "Bug 2020608 - Part 12: Replace IsPowerOfTwo with std::has_single_bit outside of js/. r=sergesanspaille,profiler-reviewers,win-reviewers,gstoll,canaltinova"

This reverts commit cec056f5d6.

Revert "Bug 2020608 - Part 11: Simplify PowerOfTwo. r=sergesanspaille,profiler-reviewers,canaltinova"

This reverts commit a2ee5b9053.

Revert "Bug 2020608 - Part 10: Prefer std::bit_width in MathAlgorithms.h. r=sergesanspaille"

This reverts commit 89d966bb97.

Revert "Bug 2020608 - Part 9: Prefer std::bit_width instead of std::countl_zero in js/src. r=sergesanspaille"

This reverts commit da9a43075a.

Revert "Bug 2020608 - Part 8: Replace CountTrailingZeroes with std::countr_zero. r=sergesanspaille"

This reverts commit d77ca273cb.

Revert "Bug 2020608 - Part 7: Replace CountLeadingZeroes32 with std::countl_zero or std::countl_one. r=sergesanspaille,nbp,profiler-reviewers,canaltinova"

This reverts commit 94929ae729.

Revert "Bug 2020608 - Part 6: Replace CountLeadingZeroes64 with std::countl_zero. r=sergesanspaille,profiler-reviewers,canaltinova"

This reverts commit 9b428168df.

Revert "Bug 2020608 - Part 5: Replace CountTrailingZeroes32 with std::countr_zero. r=sergesanspaille,manuel"

This reverts commit d3e77036b2.

Revert "Bug 2020608 - Part 4: Replace CountTrailingZeroes64 with std::countr_zero or std::countr_one. r=sergesanspaille"

This reverts commit 6a7bcee10e.

Revert "Bug 2020608 - Part 3: Replace CountPopulation32 with std::popcount. r=sergesanspaille"

This reverts commit e7b204177b.

Revert "Bug 2020608 - Part 2: Replace CountPopulation64 with std::popcount. r=sergesanspaille"

This reverts commit 1d6f98a622.

Revert "Bug 2020608 - Part 1: Add <bit> C++20 definitions to std.py. r=sergesanspaille"

This reverts commit 3ee4c6dcab.
2026-03-13 21:11:22 +00:00
André Bargull cec056f5d6 Bug 2020608 - Part 12: Replace IsPowerOfTwo with std::has_single_bit outside of js/. r=sergesanspaille,profiler-reviewers,win-reviewers,gstoll,canaltinova
`mozilla::IsPowerOfTwo` is used in more code than the previous functions, so split
up the updates in three parts. This part updates non-SpiderMonkey code to use
`std::has_single_bit`. The next part updates SpiderMonkey code and the last part
finally removes `mozilla::IsPowerOfTwo`.

Differential Revision: https://phabricator.services.mozilla.com/D286320
2026-03-13 20:20:10 +00:00
Damien Carver c155ffa4a1 Bug 2014999 - Use the ternary operator in the schema of TimerMarker. r=canaltinova
Differential Revision: https://phabricator.services.mozilla.com/D285745
2026-03-05 15:10:28 +00:00
Justin Link 71be0e2c2b Bug 1881627: HiResWindowsMonitor switches between hi- and lo-res timers depending on the tolerance of the wait. r=smaug,gstoll
Differential Revision: https://phabricator.services.mozilla.com/D278157
2026-03-04 21:14:21 +00:00
Justin Link e1dfedda99 Bug 1881627: Compute wait delay tolerance in TimerThread r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D278156
2026-03-04 21:14:18 +00:00
Justin Link 01c7c012c9 Bug 1881627: Implemented HiResWindowsMonitor and used it in TimerThread (on Windows) r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D274769
2026-03-04 21:14:16 +00:00
Justin Link 0c9bc750f3 Bug 1881627: Got rid of WindowsTimerFrequencyManager and related machinery r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D274767
2026-03-04 21:14:10 +00:00
agoloman 5fcce17503 Revert "Bug 1881627: Handle the possibility of failing to create the hi-res timer in HiResWindowsMonitor r=smaug,gstoll" for causing multiple failures.
This reverts commit 64f1200593.

Revert "Bug 1881627: HiResWindowsMonitor switches between hi- and lo-res timers depending on the tolerance of the wait. r=smaug,gstoll"

This reverts commit b26c5e86c4.

Revert "Bug 1881627: Compute wait delay tolerance in TimerThread r=smaug"

This reverts commit 35fff48605.

Revert "Bug 1881627: Implemented HiResWindowsMonitor and used it in TimerThread (on Windows) r=smaug"

This reverts commit 9a0f2b30a0.

Revert "Bug 1881627: Templated *MonitorAuto* r=smaug"

This reverts commit 695384e7e0.

Revert "Bug 1881627: Got rid of WindowsTimerFrequencyManager and related machinery r=smaug"

This reverts commit 2f1747630b.
2026-02-24 21:53:00 +00:00
Justin Link b26c5e86c4 Bug 1881627: HiResWindowsMonitor switches between hi- and lo-res timers depending on the tolerance of the wait. r=smaug,gstoll
Differential Revision: https://phabricator.services.mozilla.com/D278157
2026-02-24 15:16:41 +00:00
Justin Link 35fff48605 Bug 1881627: Compute wait delay tolerance in TimerThread r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D278156
2026-02-24 15:16:39 +00:00
Justin Link 9a0f2b30a0 Bug 1881627: Implemented HiResWindowsMonitor and used it in TimerThread (on Windows) r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D274769
2026-02-24 15:16:36 +00:00
Justin Link 2f1747630b Bug 1881627: Got rid of WindowsTimerFrequencyManager and related machinery r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D274767
2026-02-24 15:16:30 +00:00
Damien Carver a510771d0e Bug 1992695 - Add missing hidden fields to profiler marker schemas. r=necko-reviewers,profiler-reviewers,canaltinova
Differential Revision: https://phabricator.services.mozilla.com/D281397
2026-02-11 09:46:02 +00:00
Damien Carver d4d96c1939 Bug 1979356 - Remove the "searchable" flag from marker schema fields r=necko-reviewers,profiler-reviewers,toolkit-telemetry-reviewers,canaltinova,jesup
Differential Revision: https://phabricator.services.mozilla.com/D281769
2026-02-06 14:49:32 +00:00
Jens Stutte dbeb0cf657 Bug 2000185 - Remove suppression for Windows of an assertion in ComputeWakeupTimeFromTimers. r=xpcom-reviewers,emilio
Bug 1995254 fixed the underlying problem that made this assertion trip occasionally in CI.

Together we can remove an already unused DEBUG only function in TimeStamp that was added in bug 1829983 when investigating an intermittent faliure on Windows with this assertion.

Differential Revision: https://phabricator.services.mozilla.com/D272995
2025-11-19 11:29:03 +00:00
Jens Stutte a3ca81c0fa Bug 1999509 - Ensure PostTimerEvent will not release anything important while holding the monitor's lock. r=xpcom-reviewers,nika
Short living event targets (like SharedThreadPool or TaskQueue or even dying threads)
must never be released while we hold TimerThread's monitor locked. PostTimerEvent needs
to keep a strong reference to the target before unlocking and must release that
reference before re-acquiring the lock. The same goes for nsTimerEvent.

Differential Revision: https://phabricator.services.mozilla.com/D257966
2025-11-11 14:11:09 +00:00
Jeff Muizelaar a9bdd0b61d Bug 1996304 - Rename AUTO_PROFILER_TRACING_MARKER to AUTO_PROFILER_MARKER. r=mstange,profiler-reviewers,layout-reviewers,emilio
This also drops the category argument. The category string was confusing
because it ends up a field of the marker and not the actual category which is
an enum. Having the category as a field isn't really helpful.

This also sets us up for unifying AUTO_PROFILER_MARKER and
AUTO_PROFILER_MARKER_UNTYPED which become basically the same.

Differential Revision: https://phabricator.services.mozilla.com/D269992
2025-11-01 18:52:58 +00:00
Cristian Tuns dc43a0df23 Revert "Bug 1996304 - Rename AUTO_PROFILER_TRACING_MARKER to AUTO_PROFILER_MARKER. r=mstange,profiler-reviewers,layout-reviewers,emilio" for causing gtest failures in GeckoProfiler.Markers
This reverts commit 3f41ce3a69.
2025-11-01 10:51:36 +00:00
Jeff Muizelaar 3f41ce3a69 Bug 1996304 - Rename AUTO_PROFILER_TRACING_MARKER to AUTO_PROFILER_MARKER. r=mstange,profiler-reviewers,layout-reviewers,emilio
This also drops the category argument. The category string was confusing
because it ends up a field of the marker and not the actual category which is
an enum. Having the category as a field isn't really helpful.

This also sets us up for unifying AUTO_PROFILER_MARKER and
AUTO_PROFILER_MARKER_UNTYPED which become basically the same.

Differential Revision: https://phabricator.services.mozilla.com/D269992
2025-11-01 02:29:14 +00:00
Sandor Molnar 493110acba Revert "Bug 1996304 - Rename AUTO_PROFILER_TRACING_MARKER to AUTO_PROFILER_MARKER. r=mstange,profiler-reviewers,layout-reviewers,emilio" for causing cppunit perma failures
This reverts commit eba2838e1b.
2025-10-31 23:54:16 +00:00
Jeff Muizelaar eba2838e1b Bug 1996304 - Rename AUTO_PROFILER_TRACING_MARKER to AUTO_PROFILER_MARKER. r=mstange,profiler-reviewers,layout-reviewers,emilio
This also drops the category argument. The category string was confusing
because it ends up a field of the marker and not the actual category which is
an enum. Having the category as a field isn't really helpful.

This also sets us up for unifying AUTO_PROFILER_MARKER and
AUTO_PROFILER_MARKER_UNTYPED which become basically the same.

Differential Revision: https://phabricator.services.mozilla.com/D269992
2025-10-31 20:32:15 +00:00
Alexandru Marc 3eee106683 Revert "Bug 1996304 - Rename AUTO_PROFILER_TRACING_MARKER to AUTO_PROFILER_MARKER. r=mstange,profiler-reviewers,layout-reviewers,emilio" for causing build bustages @ ETWTools.h
This reverts commit 38cd0df829.
2025-10-31 16:17:31 +00:00
Jeff Muizelaar 38cd0df829 Bug 1996304 - Rename AUTO_PROFILER_TRACING_MARKER to AUTO_PROFILER_MARKER. r=mstange,profiler-reviewers,layout-reviewers,emilio
This also drops the category argument. The category string was confusing
because it ends up a field of the marker and not the actual category which is
an enum. Having the category as a field isn't really helpful.

This also sets us up for unifying AUTO_PROFILER_MARKER and
AUTO_PROFILER_MARKER_UNTYPED which become basically the same.

Differential Revision: https://phabricator.services.mozilla.com/D269992
2025-10-31 15:39:08 +00:00
serge-sans-paille 1667ec582b Bug 1995723 - Remove unused inclusion of mozilla/ArrayUtils.h r=necko-reviewers,application-update-reviewers,media-playback-reviewers,profiler-reviewers,win-reviewers,firefox-svg-reviewers,layout-reviewers,gstoll,canaltinova,bytesized,alwu,dholbert
Differential Revision: https://phabricator.services.mozilla.com/D269573
2025-10-23 07:30:37 +00:00
uniqueident 5b80575fda Bug 1957059 - Removed the "{marker.name} - " from all TableLabel and SetTableLabel calls in order to clean up existing marcher schemas in the profiler. r=canaltinova,profiler-reviewers,win-reviewers,toolkit-telemetry-reviewers,gstoll
Differential Revision: https://phabricator.services.mozilla.com/D263049
2025-09-16 13:51:07 +00:00
Nika Layzell 7d39c30b5b Bug 1979013 - Part 2: Require nsITimer API callers to provide a nsACString, r=xpcom-reviewers,media-playback-reviewers,webrtc-reviewers,profiler-reviewers,dom-storage-reviewers,toolkit-telemetry-reviewers,firefox-style-system-reviewers,mstange,emz,bwc,janv,emilio,padenot
This avoids the small overhead and potential for bugs from the previous
approach of assuming all `const char*` arguments passed to `nsITimer`
initializers are string literals, by instead requiring the argument to be a
`const nsACString&`. This involves changing all callsites to pass a `""_ns`
string literal down instead of a bare string literal.

It appears that while there were currently no buggy callers which
would've provided a dynamic string, there was at least one piece of code
(nsRepeatService::Start) which did pass down a raw char* which may be
dynamically allocated (all callers pass down `nsLiteralCString` so we're
actually OK here right now, but this was a footgun).

Differential Revision: https://phabricator.services.mozilla.com/D261032
2025-08-29 16:18:25 +00:00
Nika Layzell f8cc60a090 Bug 1979013 - Part 1: Eagerly fetch name for timer callbacks, r=xpcom-reviewers,mccr8,necko-reviewers,valentin
This avoids risks which can be caused by reading the name for things
such as the profiler. By fetching the name from the callback when the
nsITimer is initialized, we avoid potential race conditions, and also
avoid the potential for re-entrancy when reading the name from a timer.

As part of this change, timer names are now always stored as a
`nsCString` (as they may be dynamic due to JS or custom nsINamed
implementations). The `const char*` arguments passed to function and closure
based constructors are assumed to be string literals, and passed to
`AssignLiteral`.

Differential Revision: https://phabricator.services.mozilla.com/D261031
2025-08-29 16:18:21 +00:00
iulian moraru f5d6849317 Revert "Bug 1979013: apply code formatting via Lando" for causing windows build bustages on MFTEncoder.cpp.
This reverts commit 8c929cc018.

Revert "Bug 1979013 - Part 2: Require nsITimer API callers to provide a nsACString, r=xpcom-reviewers,media-playback-reviewers,webrtc-reviewers,profiler-reviewers,dom-storage-reviewers,toolkit-telemetry-reviewers,firefox-style-system-reviewers,mstange,emz,bwc,janv,emilio,padenot"

This reverts commit e01c0a6a32.

Revert "Bug 1979013 - Part 1: Eagerly fetch name for timer callbacks, r=xpcom-reviewers,mccr8"

This reverts commit 9f8e73c163.
2025-08-27 23:00:09 +00:00
Nika Layzell e01c0a6a32 Bug 1979013 - Part 2: Require nsITimer API callers to provide a nsACString, r=xpcom-reviewers,media-playback-reviewers,webrtc-reviewers,profiler-reviewers,dom-storage-reviewers,toolkit-telemetry-reviewers,firefox-style-system-reviewers,mstange,emz,bwc,janv,emilio,padenot
This avoids the small overhead and potential for bugs from the previous
approach of assuming all `const char*` arguments passed to `nsITimer`
initializers are string literals, by instead requiring the argument to be a
`const nsACString&`. This involves changing all callsites to pass a `""_ns`
string literal down instead of a bare string literal.

It appears that while there were currently no buggy callers which
would've provided a dynamic string, there was at least one piece of code
(nsRepeatService::Start) which did pass down a raw char* which may be
dynamically allocated (all callers pass down `nsLiteralCString` so we're
actually OK here right now, but this was a footgun).

Differential Revision: https://phabricator.services.mozilla.com/D261032
2025-08-27 22:04:15 +00:00
Nika Layzell 9f8e73c163 Bug 1979013 - Part 1: Eagerly fetch name for timer callbacks, r=xpcom-reviewers,mccr8
This avoids risks which can be caused by reading the name for things
such as the profiler. By fetching the name from the callback when the
nsITimer is initialized, we avoid potential race conditions, and also
avoid the potential for re-entrancy when reading the name from a timer.

As part of this change, timer names are now always stored as a
`nsCString` (as they may be dynamic due to JS or custom nsINamed
implementations). The `const char*` arguments passed to function and closure
based constructors are assumed to be string literals, and passed to
`AssignLiteral`.

Differential Revision: https://phabricator.services.mozilla.com/D261031
2025-08-27 22:04:11 +00:00
Nazım Can Altınova 9469d2d919 Bug 1980588 - Add PayloadFlags to the old and Rust marker API r=mstange,profiler-reviewers
This changes a lot of places, but it's essentially just find and
replace. We had to change this old marker API, because the new API
uses this one to serialize the marker schema fields.

This patch removes the AddKey{Label,}FormatSearchable methods and
switches to use the original AddKey{Label,}Format methods with an
optional parameter instead to make sure that we can pass multiple flags
instead of just Searchable.

For Rust, since we can't have default argument values, we had to create
a new method for them.

Differential Revision: https://phabricator.services.mozilla.com/D260465
2025-08-27 22:02:38 +00:00
Jens Stutte f68da43b49 Bug 1961386 - part 6: Use binary search in Add/RemoveTimerInternal. r=xpcom-reviewers,nika,jlink
The linear scan for the insertion point can be replaced by a binary search.

All the other logic of finding empty slots or removing entries remains unchanged by this.

Resulting complexity:
- Changed: AddTimer becomes minimum O(log[n]) (due to the lower boundary of the binary search) to maximum O(n) depending on the luck we have with finding empty slots.
- Changed: RemoveTimer becomes O(log(n)) always (for the binary search) as we postpone the removal of canceled timers to happen in the Run loop or through re-use.
- Extracting the next timer to fire on the TimerThread remains always O(n) (but happens on the timer thread, where it might disturb less).
- Removing the leading canceled timers remains always O(n) (but happens on the timer thread, where it might disturb less).

Differential Revision: https://phabricator.services.mozilla.com/D249902
2025-07-04 20:10:23 +00:00
Jens Stutte 967b715695 Bug 1961386 - part 5: Simplify TimerThread::Entry and AddTimerInternal. r=xpcom-reviewers,nika,jlink
Entry's lifecycle was strictly bound to (Set)IsInTimerThread. It can become a simple struct which will ease its handling in sorted arrays (or sets).
We simply make explicit calls to SetIsInTimerThread where the add/remove occurs.

AddTimerInternal's many if clauses can be re-arranged in a simpler loop, the way of re-using empty slots should be unchanged by this. This enables us also to not need the ctor for canceled timers in Entry.
Note also that the single loop with swap is faster than scanning first for empty slots and in the not unlikely case of no empty slots moving the tail of timers then.

Differential Revision: https://phabricator.services.mozilla.com/D249901
2025-07-04 20:10:20 +00:00
Jens Stutte 3949ce093c Bug 1961386 - part 3: Substitute timer local mGeneration with TimerThread global sequence. r=xpcom-reviewers,nika,jlink
This will help us later to craft stable and unique sort conditions for TimerThread::mTimers, enabling binary search on the array.

Differential Revision: https://phabricator.services.mozilla.com/D249899
2025-07-04 20:10:14 +00:00
Jens Stutte 4a46ae75c3 Bug 1961386 - part 2: Add MOZ_GUARDED_BY to mTimeout in nsTimerImpl. r=xpcom-reviewers,nika,jlink
Given TimerThread::Entry contains a copy of the timeout, we can use that everywhere we have no lock on nsTimerImpl::mMutex, relying on the invariant that the timeout must not change while the timer is in the TimerThread.
Doing so enables us to annotate it and have stricter checks.
Note that one unsafe, DEBUG-only check remains but it is explicitly annotated as such. TSAN will tell if we are safe enough.

Differential Revision: https://phabricator.services.mozilla.com/D249898
2025-07-04 20:10:11 +00:00
Jens Stutte 9fb0a0eec0 Bug 1961386 - part 1: Remove VerifyTimerListConsistency. r=xpcom-reviewers,nika,jlink
The original intent of this DEBUG only function was to verify our book-keeping.
However, it prevents us from applying strict thread-safety checks on nsTimerImpl::mTimeout.
Given we are going to change our book-keeping up the stack, we can just remove it but:

- add an assertion directly before PostTimerEvent if the timeout remained unchanged
- add placeholder comments where to check for the correct sort order.

Differential Revision: https://phabricator.services.mozilla.com/D249897
2025-07-04 20:10:08 +00:00
Serban Stanca 8507096e4b Revert "Bug 1961386 - part 6: Use binary search in Add/RemoveTimerInternal. r=xpcom-reviewers,nika,jlink" for causing devtools failures in browser_rules_mark_overridden_layers.js.
This reverts commit d0da8faf38.

This reverts commit 290c897a56.

This reverts commit feb3956985.

This reverts commit eb07412c3e.

This reverts commit 31a063c7e3.

This reverts commit c53ea72851.
2025-07-02 18:48:24 +00:00
Jens Stutte d0da8faf38 Bug 1961386 - part 6: Use binary search in Add/RemoveTimerInternal. r=xpcom-reviewers,nika,jlink
The linear scan for the insertion point can be replaced by a binary search.

All the other logic of finding empty slots or removing entries remains unchanged by this.

Resulting complexity:
- Changed: AddTimer becomes minimum O(log[n]) (due to the lower boundary of the binary search) to maximum O(n) depending on the luck we have with finding empty slots.
- Changed: RemoveTimer becomes O(log(n)) always (for the binary search) as we postpone the removal of canceled timers to happen in the Run loop or through re-use.
- Extracting the next timer to fire on the TimerThread remains always O(n) (but happens on the timer thread, where it might disturb less).
- Removing the leading canceled timers remains always O(n) (but happens on the timer thread, where it might disturb less).

Differential Revision: https://phabricator.services.mozilla.com/D249902
2025-07-02 15:08:12 +00:00
Jens Stutte 290c897a56 Bug 1961386 - part 5: Simplify TimerThread::Entry and AddTimerInternal. r=xpcom-reviewers,nika,jlink
Entry's lifecycle was strictly bound to (Set)IsInTimerThread. It can become a simple struct which will ease its handling in sorted arrays (or sets).
We simply make explicit calls to SetIsInTimerThread where the add/remove occurs.

AddTimerInternal's many if clauses can be re-arranged in a simpler loop, the way of re-using empty slots should be unchanged by this. This enables us also to not need the ctor for canceled timers in Entry.
Note also that the single loop with swap is faster than scanning first for empty slots and in the not unlikely case of no empty slots moving the tail of timers then.

Differential Revision: https://phabricator.services.mozilla.com/D249901
2025-07-02 15:08:09 +00:00
Jens Stutte eb07412c3e Bug 1961386 - part 3: Substitute timer local mGeneration with TimerThread global sequence. r=xpcom-reviewers,nika,jlink
This will help us later to craft stable and unique sort conditions for TimerThread::mTimers, enabling binary search on the array.

Differential Revision: https://phabricator.services.mozilla.com/D249899
2025-07-02 15:08:03 +00:00