Skip to content

Conversation

@chocolacula
Copy link
Contributor

Objective

The current Instant fallback implementation in bevy_platform contains a bug on ARM CPUs, such as Apple Silicon. It appears only under specific conditions — when the std feature is disabled for desktop builds on ARM. For web builds, as I can see, the time implementation differs and does not exhibit this issue. Still, this remains a bug.

In the current implementation, the code reads the system counter value (tick count) and incorrectly interprets it as nanoseconds. We have to additionally divide number by frequency to obtain elapsed time.

Solution

Query the system counter frequency and compute nanoseconds using the correct formula:

// number of second in nanos resolution
 (ticks / freq) * 1_000_000_000 +         // integer part
((ticks % freq) * 1_000_000_000) / freq   // fractional part

Testing

A test was added, but verifying this fix is tricky since it’s platform-specific.
The test checks the correct condition only on aarch64 when the std feature is disabled — which is somewhat cumbersome to configure in bevy’s root project. The best option I found for development is disable crate::cfg::std branch in bevy_platform/src/time/mod.rs

For a visual sanity check, you can run the move_sprite example, if the time calculation is incorrect, the sprite’s movement appears roughly 10x slower than expected.

@chocolacula chocolacula force-pushed the aarch64-time branch 2 times, most recently from 02c4a4c to 3fac947 Compare October 28, 2025 12:41
@github-actions
Copy link
Contributor

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-21677

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

2 similar comments
@github-actions
Copy link
Contributor

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-21677

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

@github-actions
Copy link
Contributor

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-21677

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

@github-actions
Copy link
Contributor

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-21677

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

1 similar comment
@github-actions
Copy link
Contributor

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-21677

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

@github-actions
Copy link
Contributor

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-21677

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

@alice-i-cecile alice-i-cecile added C-Machine-Specific This bug is isolated to specific hardware or driver configurations A-Utils Utility functions and types S-Needs-Review Needs reviewer attention (from anyone!) to move forward O-Embedded Weird hardware and no_std platforms labels Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Utils Utility functions and types C-Machine-Specific This bug is isolated to specific hardware or driver configurations O-Embedded Weird hardware and no_std platforms S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants