Uh oh!
There was an error while loading. Please reload this page.
[native] Drop <chrono> from the timing code - #12550
Conversation
There was a problem hiding this comment.
Copilot review overview
Review tier: Lite
Findings: 1
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
src/native/common/include/runtime-base/timing-internal.hh — Suggestion (documentation): The comment above time_interval says “whole milliseconds”, which can… |
What changed in this PR
This PR advances the CoreCLR “drop-libc++ headers” effort by removing <chrono> from native timing code paths and representing timing points/intervals as a plain uint64_t nanosecond count, while preserving the existing timing output format relied on by performance tooling.
Changes:
- Replace
std::chrono-tagged time points withuint64_tnanosecond timestamps (time_point) and compute durations via integer arithmetic. - Introduce a shared
time_intervalhelper to centralize the seconds / total-milliseconds / nanoseconds-within-millisecond split used in multiple log formats. - Switch the timing clock source from
CLOCK_MONOTONIC_RAWtoCLOCK_MONOTONICand remove an unused<chrono>include.
| File | Description |
|---|---|
| src/native/mono/monodroid/monodroid-glue.cc | Use time_interval for JIT timing log formatting instead of std::chrono duration casts. |
| src/native/common/runtime-base/timing-internal.cc | Remove <chrono> usage and format accumulated timing results via time_interval. |
| src/native/common/include/runtime-base/timing.hh | Use time_interval for managed timing sequence log formatting; initialize start/end as 0. |
| src/native/common/include/runtime-base/timing-internal.hh | Redefine time_point as uint64_t, add time_interval, remove <chrono>, and update get_time() implementation/clock. |
| src/native/common/include/runtime-base/mainthread-dso-loader.hh | Drop unused <chrono> include. |
Uh oh!
There was an error while loading. Please reload this page.
f47cca6 to
0d37fc3Compare864a3eb to
ce91e4cComparece91e4c to
8941965Compare8941965 to
bf9157bComparebf9157b to
67df971Compare67df971 to
f50052bCompare`FastTiming::get_time()` already read the clock with `clock_gettime()`; `std::chrono::steady_clock` was only used as the type tag of the `chrono::time_point` the result was wrapped in. Store the timestamps as a plain `uint64_t` nanosecond count instead and drop `<chrono>` from the four files that included it (it was entirely unused in mainthread-dso-loader.hh). All four places that formatted an interval repeated the same seconds/milliseconds/nanoseconds split, so they now share a `time_interval` helper. The split is reproduced exactly as `chrono::duration_cast` computed it, so the timing output is unchanged - this matters because the format after the first colon is parsed by our performance measuring utilities. Also read `CLOCK_MONOTONIC` rather than `CLOCK_MONOTONIC_RAW`, so that we keep using the same clock `steady_clock` was documented to use. The two differ only in that `CLOCK_MONOTONIC` is slewed by NTP, which is irrelevant at the granularity we measure. This does not remove any undefined libc++ symbols - `<chrono>` is header only - but it does shrink libnet-android.release.so by 80 bytes and removes one more libc++ header from the build. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0a35a0db-502d-48c0-8468-e73b5dd0ab2e
…tals Addresses review feedback. Both fields are totals for the whole interval and both are printed, so `milliseconds` is not milliseconds-within-the-second. The output format is consumed by performance measuring utilities, so spell this out to keep a future change from "correcting" it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0a35a0db-502d-48c0-8468-e73b5dd0ab2e
f50052b to
d350d84CompareUh oh!
There was an error while loading. Please reload this page.
simonrozsival
commented
Aug 28, 2026
Consolidated into #12545 to reduce the depth of the #12546 stack. No code changed: the commits from this PR are now part of #12545 unmodified, and the resulting tree is byte-identical. This PR sat directly on top of #12545 and touched the same files, so reviewing them together is easier than reviewing the same file across two intermediate states. |

Part of the drop-libc++ work for CoreCLR.
FastTiming::get_time()has always read the clock withclock_gettime()directly — the comment above it even says we do that to avoid calling into libc++:std::chrono::steady_clockwas then used only as the type tag of thechrono::time_pointwe wrapped the result in. So we were paying for<chrono>without using the clock it provides.This PR stores timestamps as a plain
uint64_tnanosecond count and removes<chrono>from the four files that included it. Inmainthread-dso-loader.hhthe include was entirely unused.Sharing the interval formatting
Four places repeated the same seconds / milliseconds / nanoseconds-within-the-millisecond split, so they now share one helper:
The split reproduces
chrono::duration_castexactly, including the fact that the middle field is the total milliseconds rather than a remainder. The timing output is byte-for-byte unchanged, which matters because the format after the first colon is parsed by our performance measuring utilities.I verified this rather than assuming it: a standalone harness compared the old
chronocomputation againsttime_intervalover the nine interesting edge cases (0,999999,1000000,1000001,999999999,1000000000, …,INT64_MAX) plus 2,000,000 random values — 2,000,009 checked, 0 mismatches.CLOCK_MONOTONIC_RAW → CLOCK_MONOTONIC
We now read
CLOCK_MONOTONIC, the clocksteady_clockis specified to use, instead ofCLOCK_MONOTONIC_RAW. The two differ only in thatCLOCK_MONOTONICis slewed by NTP, which is irrelevant at the granularity we measure.Results
This does not remove any undefined libc++ symbols — the count stays at 59.
<chrono>is header-only, so it never contributed any. What it does do is shrink the binary slightly and remove one more libc++ header from the build, which is a prerequisite for eventually building without libc++ headers at all:libnet-android.release.sotiming-internal.cc.o(Measured against a real rebuild of the parent commit, not remembered numbers.)
Testing
format_managed_type_namewarning).time_intervalverified againstchronoover 2,000,009 inputs as described above.