Skip to content

Commit

Permalink
Remove instant dependency when not building for web (#157)
Browse files Browse the repository at this point in the history
This dependency was introduced originally in #112.

It is a platform abstraction, but it is a tiny one and it is not harder
to just use the std type which avoids always pulling in `instant`
including for `wasm32-unknown-unknown` when not building for the web
where it has no purpose at all.

Want to have as few dependencies as possible on core low level crates
like `puffin` that almost all of our code depends on.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
  • Loading branch information
repi and emilk authored Sep 4, 2023
1 parent c277a02 commit fdbbada
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 79 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
- run: cargo fetch
- name: cargo clippy
run: cargo clippy --all-targets -- -D warnings
- name: cargo clippy wasm32-unknown-unknown WITHOUT web feature
run: cargo clippy -p puffin --target wasm32-unknown-unknown --no-default-features -- -D warnings
- name: cargo clippy wasm32
run: cargo clippy -p puffin_viewer --target wasm32-unknown-unknown --all-features --lib

Expand Down Expand Up @@ -73,7 +75,7 @@ jobs:
runs-on: ubuntu-20.04-16core
env:
# there is no published release for v0.7 yet, build from git revision
CARGO_VET_REVISION: 088586c
CARGO_VET_REVISION: 8c8b6d7a5237544c613de616a031586587f49a42
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
Expand Down
15 changes: 13 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions puffin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ zstd = ["dep:zstd", "dep:ruzstd"]
serialization = ["packing"]

# Enable this to be able to run puffin inside a browser when compiling to wasm
web = ["instant/wasm-bindgen", "dep:js-sys"]
web = ["dep:js-sys", "dep:web-time"]


[dependencies]
byteorder = { version = "1.0" }
cfg-if = "1.0"
instant = { version = "0.1" }
once_cell = "1.0"

# Optional:
Expand All @@ -54,6 +53,7 @@ zstd = { version = "0.12.3", optional = true } # native only
[target.'cfg(target_arch = "wasm32")'.dependencies]
js-sys = { version = "0.3", optional = true }
ruzstd = { version = "0.4.0", optional = true } # works on wasm
web-time = { version = "0.2", optional = true }


[dev-dependencies]
Expand Down
4 changes: 4 additions & 0 deletions puffin/src/frame_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,20 @@ compile_error!(
#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum CompressionKind {
#[allow(dead_code)] // with some feature sets
Uncompressed = 0,

/// Very fast, and lightweight dependency
#[allow(dead_code)] // with some feature sets
Lz4 = 1,

/// Big dependency, slow compression, but compresses better than lz4
#[allow(dead_code)] // with some feature sets
Zstd = 2,
}

impl CompressionKind {
#[cfg(feature = "serialization")]
fn from_u8(value: u8) -> anyhow::Result<Self> {
match value {
0 => Ok(Self::Uncompressed),
Expand Down
7 changes: 6 additions & 1 deletion puffin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,12 @@ pub fn now_ns() -> NanoSecond {
}

// This can maybe be optimized
use instant::Instant;

#[cfg(not(target_arch = "wasm32"))]
use std::time::Instant;
#[cfg(target_arch = "wasm32")]
use web_time::Instant;

use once_cell::sync::Lazy;

static START_TIME: Lazy<(NanoSecond, Instant)> =
Expand Down
2 changes: 1 addition & 1 deletion puffin_egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ include = [
[dependencies]
egui = { version = "0.22.0", default-features = false }
indexmap = { version = "1.9.1", features = ["serde"] }
instant = "0.1"
natord = "1.0.9"
once_cell = "1.7"
puffin = { version = "0.16.0", path = "../puffin", features = ["packing"] }
Expand All @@ -33,6 +32,7 @@ time = { version = "0.3.17", default-features = false, features = [
"macros",
] }
vec1 = "1.8"
web-time = "0.2"

[dev-dependencies]
eframe = { version = "0.22.0", default-features = false, features = [
Expand Down
8 changes: 4 additions & 4 deletions puffin_egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ pub struct ProfilerUi {

/// When did we last run a pass to pack all the frames?
#[cfg_attr(feature = "serde", serde(skip))]
last_pack_pass: Option<instant::Instant>,
last_pack_pass: Option<web_time::Instant>,
}

impl Default for ProfilerUi {
Expand Down Expand Up @@ -433,16 +433,16 @@ impl ProfilerUi {
}
let last_pack_pass = self
.last_pack_pass
.get_or_insert_with(instant::Instant::now);
.get_or_insert_with(web_time::Instant::now);
let time_since_last_pack = last_pack_pass.elapsed();
if time_since_last_pack > instant::Duration::from_secs(1) {
if time_since_last_pack > web_time::Duration::from_secs(1) {
puffin::profile_scope!("pack_pass");
for frame in self.all_known_frames(frame_view) {
if !self.is_selected(frame_view, frame.frame_index()) {
frame.pack();
}
}
self.last_pack_pass = Some(instant::Instant::now());
self.last_pack_pass = Some(web_time::Instant::now());
}
}

Expand Down
36 changes: 8 additions & 28 deletions supply-chain/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# cargo-vet config file

[cargo-vet]
version = "0.7"
version = "0.8"

[imports.embark]
url = "https://raw.githubusercontent.com/EmbarkStudios/rust-ecosystem/main/audits.toml"
Expand Down Expand Up @@ -71,10 +71,6 @@ criteria = "safe-to-deploy"
version = "0.11.0"
criteria = "safe-to-deploy"

[[exemptions.adler]]
version = "1.0.2"
criteria = "safe-to-deploy"

[[exemptions.ahash]]
version = "0.8.3"
criteria = "safe-to-deploy"
Expand Down Expand Up @@ -203,10 +199,6 @@ criteria = "safe-to-deploy"
version = "2.3.1"
criteria = "safe-to-deploy"

[[exemptions.fdeflate]]
version = "0.3.0"
criteria = "safe-to-deploy"

[[exemptions.gdk-pixbuf-sys]]
version = "0.15.10"
criteria = "safe-to-deploy"
Expand Down Expand Up @@ -287,10 +279,6 @@ criteria = "safe-to-deploy"
version = "0.1.12"
criteria = "safe-to-deploy"

[[exemptions.io-lifetimes]]
version = "1.0.11"
criteria = "safe-to-deploy"

[[exemptions.jni-sys]]
version = "0.3.0"
criteria = "safe-to-deploy"
Expand Down Expand Up @@ -327,10 +315,6 @@ criteria = "safe-to-deploy"
version = "0.2.1"
criteria = "safe-to-deploy"

[[exemptions.mio]]
version = "0.8.8"
criteria = "safe-to-deploy"

[[exemptions.ndk]]
version = "0.7.0"
criteria = "safe-to-deploy"
Expand Down Expand Up @@ -475,10 +459,6 @@ criteria = "safe-to-deploy"
version = "0.3.22"
criteria = "safe-to-deploy"

[[exemptions.time-core]]
version = "0.1.1"
criteria = "safe-to-deploy"

[[exemptions.time-macros]]
version = "0.2.9"
criteria = "safe-to-deploy"
Expand All @@ -503,10 +483,6 @@ criteria = "safe-to-deploy"
version = "1.6.3"
criteria = "safe-to-deploy"

[[exemptions.unicode-bidi]]
version = "0.3.13"
criteria = "safe-to-deploy"

[[exemptions.url]]
version = "2.4.0"
criteria = "safe-to-deploy"
Expand Down Expand Up @@ -539,6 +515,10 @@ criteria = "safe-to-deploy"
version = "0.30.1"
criteria = "safe-to-deploy"

[[exemptions.web-time]]
version = "0.2.0"
criteria = "safe-to-deploy"

[[exemptions.webbrowser]]
version = "0.8.10"
criteria = "safe-to-deploy"
Expand All @@ -560,23 +540,23 @@ version = "0.4.0"
criteria = "safe-to-deploy"

[[exemptions.windows-targets]]
version = "0.42.1"
version = "0.42.2"
criteria = "safe-to-deploy"

[[exemptions.windows-targets]]
version = "0.48.0"
criteria = "safe-to-deploy"

[[exemptions.windows_aarch64_gnullvm]]
version = "0.42.0"
version = "0.42.2"
criteria = "safe-to-deploy"

[[exemptions.windows_aarch64_gnullvm]]
version = "0.48.0"
criteria = "safe-to-deploy"

[[exemptions.windows_x86_64_gnullvm]]
version = "0.42.0"
version = "0.42.2"
criteria = "safe-to-deploy"

[[exemptions.windows_x86_64_gnullvm]]
Expand Down
Loading

0 comments on commit fdbbada

Please sign in to comment.