gpui: Use platform clock in action profiler (#63183)
# Objective I’m building a component library with GPUI and ran into a panic when I enabled the profiler feature for a `wasm32-unknown-unknown` build. Dispatching an action calls std::time::Instant::now(), which has no clock implementation on this target, and the browser reports time not implemented on this platform. The panic then triggers RefCell already borrowed errors and leaves the GPUI window unresponsive. The current `main` fails to compile this feature combination because the action profiler’s std::time::Instant does not match the scheduler-based timestamps in the profiler journal. I want GPUI’s action profiler to use the same cross-platform clock as the rest of the profiler and keep this configuration covered by CI. ## Solution Use `scheduler::Instant`, the scheduler crate's cross-platform instant type, for action timings so they match the rest of the GPUI profiler. Keep the existing downstream wasm check and add a separate profiler-enabled GPUI wasm check so CI covers both feature configurations. ## Testing - `cargo check --target wasm32-unknown-unknown -p gpui --no-default-features --features profiler` - `cargo -Zbuild-std=std,panic_abort check --target wasm32-unknown-unknown -p gpui_platform -p cloud_api_client --features gpui/profiler` - `cargo test -p gpui --no-default-features --features profiler profiler::` (48 tests passed) - `./script/clippy -p gpui` I ran a wasm GPUI app in Edge with WebGPU. The app opens a window and dispatches an action with `profiler` enabled. Before this change, the action produced the clock panic and follow-on borrow errors. After the fix change, the action completed and the window remained active. I did not run the browser harness in Firefox or Safari, though the wasm compile check covers the changed profiler configuration without depending on a browser. ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines); this PR has no UI changes - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable --- Release Notes: - Fixed a crash when dispatching profiled GPUI actions in web applications. --------- Co-authored-by: Anthony Eid <anthony@zed.dev>
This commit is contained in:
1 parent
e0f913b07d
commit
d4cd310edb
1 file changed
+2
-1
@@ -1,6 +1,7 @@
|
||||
use std::time::{Duration, Instant};
|
||||
use std::time::Duration;
|
||||
|
||||
use itertools::Itertools;
|
||||
use scheduler::Instant;
|
||||
|
||||
#[cfg(feature = "profiler")]
|
||||
use crate::action::Action;
|
||||
|
||||
Reference in new issue
Block a user