Skip to content

Commit cf77b5b

Browse files
authored
Remove instant dependency in favor of web-time (#767)
1 parent 93bd37d commit cf77b5b

File tree

15 files changed

+107
-83
lines changed

15 files changed

+107
-83
lines changed

.github/workflows/rapier-ci-build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ jobs:
7575
- uses: actions/checkout@v4
7676
- run: rustup target add wasm32-unknown-unknown
7777
- name: build rapier2d
78-
run: cd crates/rapier2d && cargo build --verbose --features wasm-bindgen --target wasm32-unknown-unknown;
78+
run: cd crates/rapier2d && cargo build --verbose --target wasm32-unknown-unknown;
7979
- name: build rapier3d
80-
run: cd crates/rapier3d && cargo build --verbose --features wasm-bindgen --target wasm32-unknown-unknown;
80+
run: cd crates/rapier3d && cargo build --verbose --target wasm32-unknown-unknown;
8181
build-wasm-emscripten:
8282
runs-on: ubuntu-latest
8383
env:

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
- `InteractionGroups` default value for `memberships` is now `GROUP_1` (#706)
2020
- `ImpulseJointSet::get_mut` has a new parameter `wake_up: bool`, to wake up connected bodies.
21+
- Removed unmaintained `instant` in favor of `web-time`. This effectively removes the `wasm-bindgen` transitive dependency as it's no longer needed.
2122

2223
## v0.22.0 (20 July 2024)
2324

crates/rapier2d-f64/Cargo.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ simd-nightly = ["simba/portable_simd", "simd-is-enabled"]
3636
# Do not enable this feature directly. It is automatically
3737
# enabled with the "simd-stable" or "simd-nightly" feature.
3838
simd-is-enabled = ["dep:vec_map"]
39-
wasm-bindgen = ["instant/wasm-bindgen"]
4039
serde-serialize = [
4140
"nalgebra/serde-serialize",
4241
"parry2d-f64/serde-serialize",
@@ -46,7 +45,7 @@ serde-serialize = [
4645
]
4746
enhanced-determinism = ["simba/libm_force", "parry2d-f64/enhanced-determinism"]
4847
debug-render = []
49-
profiler = ["dep:instant"] # Enables the internal profiler.
48+
profiler = ["dep:web-time"] # Enables the internal profiler.
5049

5150
# Feature used for debugging only.
5251
debug-disable-legitimate-fe-exceptions = []
@@ -66,7 +65,7 @@ required-features = ["dim2", "f64"]
6665

6766
[dependencies]
6867
vec_map = { version = "0.8", optional = true }
69-
instant = { version = "0.1", features = ["now"], optional = true }
68+
web-time = { version = "1.1", optional = true }
7069
num-traits = "0.2"
7170
nalgebra = "0.33"
7271
parry2d-f64 = "0.17.0"

crates/rapier2d/Cargo.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ simd-nightly = ["simba/portable_simd", "simd-is-enabled"]
3636
# Do not enable this feature directly. It is automatically
3737
# enabled with the "simd-stable" or "simd-nightly" feature.
3838
simd-is-enabled = ["dep:vec_map"]
39-
wasm-bindgen = ["instant/wasm-bindgen"]
4039
serde-serialize = [
4140
"nalgebra/serde-serialize",
4241
"parry2d/serde-serialize",
@@ -46,7 +45,7 @@ serde-serialize = [
4645
]
4746
enhanced-determinism = ["simba/libm_force", "parry2d/enhanced-determinism"]
4847
debug-render = []
49-
profiler = ["dep:instant"] # Enables the internal profiler.
48+
profiler = ["dep:web-time"] # Enables the internal profiler.
5049

5150
# Feature used for debugging only.
5251
debug-disable-legitimate-fe-exceptions = []
@@ -66,7 +65,7 @@ required-features = ["dim2", "f32"]
6665

6766
[dependencies]
6867
vec_map = { version = "0.8", optional = true }
69-
instant = { version = "0.1", features = ["now"], optional = true }
68+
web-time = { version = "1.1", optional = true }
7069
num-traits = "0.2"
7170
nalgebra = "0.33"
7271
parry2d = "0.17.0"

crates/rapier3d-f64/Cargo.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ simd-nightly = [
4040
# Do not enable this feature directly. It is automatically
4141
# enabled with the "simd-stable" or "simd-nightly" feature.
4242
simd-is-enabled = ["dep:vec_map"]
43-
wasm-bindgen = ["instant/wasm-bindgen"]
4443
serde-serialize = [
4544
"nalgebra/serde-serialize",
4645
"parry3d-f64/serde-serialize",
@@ -49,7 +48,7 @@ serde-serialize = [
4948
]
5049
enhanced-determinism = ["simba/libm_force", "parry3d-f64/enhanced-determinism"]
5150
debug-render = []
52-
profiler = ["dep:instant"] # Enables the internal profiler.
51+
profiler = ["dep:web-time"] # Enables the internal profiler.
5352

5453
# Feature used for debugging only.
5554
debug-disable-legitimate-fe-exceptions = []
@@ -69,7 +68,7 @@ required-features = ["dim3", "f64"]
6968

7069
[dependencies]
7170
vec_map = { version = "0.8", optional = true }
72-
instant = { version = "0.1", features = ["now"], optional = true }
71+
web-time = { version = "1.1", optional = true }
7372
num-traits = "0.2"
7473
nalgebra = "0.33"
7574
parry3d-f64 = "0.17.0"

crates/rapier3d/Cargo.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ simd-nightly = [
4040
# Do not enable this feature directly. It is automatically
4141
# enabled with the "simd-stable" or "simd-nightly" feature.
4242
simd-is-enabled = ["dep:vec_map"]
43-
wasm-bindgen = ["instant/wasm-bindgen"]
4443
serde-serialize = [
4544
"nalgebra/serde-serialize",
4645
"parry3d/serde-serialize",
@@ -49,7 +48,7 @@ serde-serialize = [
4948
]
5049
enhanced-determinism = ["simba/libm_force", "parry3d/enhanced-determinism"]
5150
debug-render = []
52-
profiler = ["dep:instant"] # Enables the internal profiler.
51+
profiler = ["dep:web-time"] # Enables the internal profiler.
5352

5453
# Feature used for debugging only.
5554
debug-disable-legitimate-fe-exceptions = []
@@ -69,7 +68,7 @@ required-features = ["dim3", "f32"]
6968

7069
[dependencies]
7170
vec_map = { version = "0.8", optional = true }
72-
instant = { version = "0.1", features = ["now"], optional = true }
71+
web-time = { version = "1.1", optional = true }
7372
num-traits = "0.2"
7473
nalgebra = "0.33"
7574
parry3d = "0.17.0"

crates/rapier_testbed2d-f64/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ needless_lifetimes = "allow"
4848
nalgebra = { version = "0.33", features = ["rand", "glam027"] }
4949
rand = "0.8"
5050
rand_pcg = "0.3"
51-
instant = { version = "0.1", features = ["web-sys", "now"] }
51+
web-time = { version = "1.1" }
5252
bitflags = "2"
5353
num_cpus = { version = "1", optional = true }
5454
wrapped2d = { version = "0.4", optional = true }

crates/rapier_testbed2d/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ needless_lifetimes = "allow"
4848
nalgebra = { version = "0.33", features = ["rand", "glam027"] }
4949
rand = "0.8"
5050
rand_pcg = "0.3"
51-
instant = { version = "0.1", features = ["web-sys", "now"] }
51+
web-time = { version = "1.1" }
5252
bitflags = "2"
5353
num_cpus = { version = "1", optional = true }
5454
wrapped2d = { version = "0.4", optional = true }

crates/rapier_testbed3d-f64/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ needless_lifetimes = "allow"
5050
nalgebra = { version = "0.33", features = ["rand", "glam027"] }
5151
rand = "0.8"
5252
rand_pcg = "0.3"
53-
instant = { version = "0.1", features = ["web-sys", "now"] }
53+
web-time = { version = "1.1" }
5454
bitflags = "2"
5555
num_cpus = { version = "1", optional = true }
5656
crossbeam = "0.8"

crates/rapier_testbed3d/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ needless_lifetimes = "allow"
4848
nalgebra = { version = "0.33", features = ["rand", "glam027"] }
4949
rand = "0.8"
5050
rand_pcg = "0.3"
51-
instant = { version = "0.1", features = ["web-sys", "now"] }
51+
web-time = { version = "1.1" }
5252
bitflags = "2"
5353
glam = { version = "0.27", optional = true } # For Physx
5454
num_cpus = { version = "1", optional = true }

src/counters/mod.rs

+29-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Counters for benchmarking various parts of the physics engine.
22
3+
use core::time::Duration;
34
use std::fmt::{Display, Formatter, Result};
45

56
pub use self::ccd_counters::CCDCounters;
@@ -76,11 +77,16 @@ impl Counters {
7677
}
7778
}
7879

79-
/// Total time spent for one of the physics engine.
80-
pub fn step_time(&self) -> f64 {
80+
/// Total time spent for one of the physics engine.
81+
pub fn step_time(&self) -> Duration {
8182
self.step_time.time()
8283
}
8384

85+
/// Total time spent for one of the physics engine, in milliseconds.
86+
pub fn step_time_ms(&self) -> f64 {
87+
self.step_time.time_ms()
88+
}
89+
8490
/// Notify that the custom operation has started.
8591
pub fn custom_started(&mut self) {
8692
if self.enabled {
@@ -96,10 +102,15 @@ impl Counters {
96102
}
97103

98104
/// Total time of a custom event.
99-
pub fn custom_time(&self) -> f64 {
105+
pub fn custom_time(&self) -> Duration {
100106
self.custom.time()
101107
}
102108

109+
/// Total time of a custom event, in milliseconds.
110+
pub fn custom_time_ms(&self) -> f64 {
111+
self.custom.time_ms()
112+
}
113+
103114
/// Set the number of constraints generated.
104115
pub fn set_nconstraints(&mut self, n: usize) {
105116
self.solver.nconstraints = n;
@@ -129,7 +140,7 @@ impl Counters {
129140
}
130141

131142
macro_rules! measure_method {
132-
($started:ident, $stopped:ident, $time:ident, $info:ident. $timer:ident) => {
143+
($started:ident, $stopped:ident, $time_ms:ident, $info:ident. $timer:ident) => {
133144
impl Counters {
134145
/// Start this timer.
135146
pub fn $started(&mut self) {
@@ -145,10 +156,10 @@ macro_rules! measure_method {
145156
}
146157
}
147158

148-
/// Gets the time elapsed for this timer.
149-
pub fn $time(&self) -> f64 {
159+
/// Gets the time elapsed for this timer, in milliseconds.
160+
pub fn $time_ms(&self) -> f64 {
150161
if self.enabled {
151-
self.$info.$timer.time()
162+
self.$info.$timer.time_ms()
152163
} else {
153164
0.0
154165
}
@@ -160,63 +171,63 @@ macro_rules! measure_method {
160171
measure_method!(
161172
update_started,
162173
update_completed,
163-
update_time,
174+
update_time_ms,
164175
stages.update_time
165176
);
166177
measure_method!(
167178
collision_detection_started,
168179
collision_detection_completed,
169-
collision_detection_time,
180+
collision_detection_time_ms,
170181
stages.collision_detection_time
171182
);
172183
measure_method!(
173184
island_construction_started,
174185
island_construction_completed,
175-
island_construction_time,
186+
island_construction_time_ms,
176187
stages.island_construction_time
177188
);
178189
measure_method!(
179190
solver_started,
180191
solver_completed,
181-
solver_time,
192+
solver_time_ms,
182193
stages.solver_time
183194
);
184-
measure_method!(ccd_started, ccd_completed, ccd_time, stages.ccd_time);
195+
measure_method!(ccd_started, ccd_completed, ccd_time_ms, stages.ccd_time);
185196
measure_method!(
186197
query_pipeline_update_started,
187198
query_pipeline_update_completed,
188-
query_pipeline_update_time,
199+
query_pipeline_update_time_ms,
189200
stages.query_pipeline_time
190201
);
191202

192203
measure_method!(
193204
assembly_started,
194205
assembly_completed,
195-
assembly_time,
206+
assembly_time_ms,
196207
solver.velocity_assembly_time
197208
);
198209
measure_method!(
199210
velocity_resolution_started,
200211
velocity_resolution_completed,
201-
velocity_resolution_time,
212+
velocity_resolution_time_ms,
202213
solver.velocity_resolution_time
203214
);
204215
measure_method!(
205216
velocity_update_started,
206217
velocity_update_completed,
207-
velocity_update_time,
218+
velocity_update_time_ms,
208219
solver.velocity_update_time
209220
);
210221
measure_method!(
211222
broad_phase_started,
212223
broad_phase_completed,
213-
broad_phase_time,
224+
broad_phase_time_ms,
214225
cd.broad_phase_time
215226
);
216227
measure_method!(
217228
narrow_phase_started,
218229
narrow_phase_completed,
219-
narrow_phase_time,
230+
narrow_phase_time_ms,
220231
cd.narrow_phase_time
221232
);
222233

src/counters/timer.rs

+19-11
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
1-
use std::fmt::{Display, Error, Formatter};
1+
use std::{
2+
fmt::{Display, Error, Formatter},
3+
time::Duration,
4+
};
25

36
/// A timer.
47
#[derive(Copy, Clone, Debug, Default)]
58
pub struct Timer {
6-
time: f64,
9+
time: Duration,
710
#[allow(dead_code)] // The field isn’t used if the `profiler` feature isn’t enabled.
8-
start: Option<f64>,
11+
start: Option<std::time::Instant>,
912
}
1013

1114
impl Timer {
1215
/// Creates a new timer initialized to zero and not started.
1316
pub fn new() -> Self {
1417
Timer {
15-
time: 0.0,
18+
time: Duration::from_secs(0),
1619
start: None,
1720
}
1821
}
1922

2023
/// Resets the timer to 0.
2124
pub fn reset(&mut self) {
22-
self.time = 0.0
25+
self.time = Duration::from_secs(0)
2326
}
2427

2528
/// Start the timer.
2629
pub fn start(&mut self) {
2730
#[cfg(feature = "profiler")]
2831
{
29-
self.time = 0.0;
30-
self.start = Some(instant::now());
32+
self.time = Duration::from_secs(0);
33+
self.start = Some(web_time::Instant::now());
3134
}
3235
}
3336

@@ -36,7 +39,7 @@ impl Timer {
3639
#[cfg(feature = "profiler")]
3740
{
3841
if let Some(start) = self.start {
39-
self.time += instant::now() - start;
42+
self.time += web_time::Instant::now().duration_since(start);
4043
}
4144
self.start = None;
4245
}
@@ -46,18 +49,23 @@ impl Timer {
4649
pub fn resume(&mut self) {
4750
#[cfg(feature = "profiler")]
4851
{
49-
self.start = Some(instant::now());
52+
self.start = Some(web_time::Instant::now());
5053
}
5154
}
5255

5356
/// The measured time between the last `.start()` and `.pause()` calls.
54-
pub fn time(&self) -> f64 {
57+
pub fn time(&self) -> Duration {
5558
self.time
5659
}
60+
61+
/// The measured time in milliseconds between the last `.start()` and `.pause()` calls.
62+
pub fn time_ms(&self) -> f64 {
63+
self.time.as_secs_f64() * 1000.0
64+
}
5765
}
5866

5967
impl Display for Timer {
6068
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
61-
write!(f, "{}s", self.time)
69+
write!(f, "{}ms", self.time_ms())
6270
}
6371
}

0 commit comments

Comments
 (0)