DioxusLabs / taffy

A high performance rust-powered UI layout library
https://docs.rs/taffy
Other
2.1k stars 107 forks source link

Migrate from lazy_static to once_cell #81

Closed james7132 closed 2 years ago

james7132 commented 2 years ago

What problem does this solve or what need does it fill?

lazy_static involves macros, takes a bit longer to compile, and once_cell provides more flexible ways on the way to being added to std.

What solution would you like?

Replace all usages of lazy_static with static VAR: Lazy<T>.

One potential drawback is that lazy_static supports spin-waiting on the result, while Lazy doesn't. I don't think any of the crate's usages are perf-bound by this though.

What alternative(s) have you considered?

Leave it as is.

Weibye commented 2 years ago

Looking at the dependency tree, it is criterion which is reason lazy_static is included.

sprawl v0.1.0
├── arrayvec v0.7.2
├── hash32 v0.2.1
│   └── byteorder v1.4.3
├── hash32-derive v0.1.1 (proc-macro)
│   ├── proc-macro2 v1.0.39
│   │   └── unicode-ident v1.0.0
│   ├── quote v1.0.18
│   │   └── proc-macro2 v1.0.39 (*)
│   └── syn v1.0.95
│       ├── proc-macro2 v1.0.39 (*)
│       ├── quote v1.0.18 (*)
│       └── unicode-ident v1.0.0
├── heapless v0.7.13
│   ├── hash32 v0.2.1 (*)
│   ├── spin v0.9.3
│   │   └── lock_api v0.4.7
│   │       └── scopeguard v1.1.0
│   │       [build-dependencies]
│   │       └── autocfg v1.1.0
│   └── stable_deref_trait v1.2.0
│   [build-dependencies]
│   └── rustc_version v0.4.0
│       └── semver v1.0.9
├── num-traits v0.2.15
│   [build-dependencies]
│   └── autocfg v1.1.0
└── typenum v1.15.0
[dev-dependencies]
└── criterion v0.3.5
    ├── atty v0.2.14
    │   └── winapi v0.3.9
    ├── cast v0.2.7
    │   [build-dependencies]
    │   └── rustc_version v0.4.0 (*)
    ├── clap v2.34.0
    │   ├── bitflags v1.3.2
    │   ├── textwrap v0.11.0
    │   │   └── unicode-width v0.1.9
    │   └── unicode-width v0.1.9
    ├── criterion-plot v0.4.4
    │   ├── cast v0.2.7 (*)
    │   └── itertools v0.10.3
    │       └── either v1.6.1
    ├── csv v1.1.6
    │   ├── bstr v0.2.17
    │   │   ├── lazy_static v1.4.0                       <------------
    │   │   ├── memchr v2.5.0
    │   │   ├── regex-automata v0.1.10
    │   │   └── serde v1.0.137
    │   ├── csv-core v0.1.10
    │   │   └── memchr v2.5.0
    │   ├── itoa v0.4.8
    │   ├── ryu v1.0.10
    │   └── serde v1.0.137
    ├── itertools v0.10.3 (*)
    ├── lazy_static v1.4.0                                <------------
    ├── num-traits v0.2.15 (*)
    ├── oorandom v11.1.3
    ├── plotters v0.3.1
    │   ├── num-traits v0.2.15 (*)
    │   ├── plotters-backend v0.3.2
    │   └── plotters-svg v0.3.1
    │       └── plotters-backend v0.3.2
    ├── rayon v1.5.3
    │   ├── crossbeam-deque v0.8.1
    │   │   ├── cfg-if v1.0.0
    │   │   ├── crossbeam-epoch v0.9.8
    │   │   │   ├── cfg-if v1.0.0
    │   │   │   ├── crossbeam-utils v0.8.8
    │   │   │   │   ├── cfg-if v1.0.0
    │   │   │   │   └── lazy_static v1.4.0            <------------
    │   │   │   ├── lazy_static v1.4.0                <------------
    │   │   │   ├── memoffset v0.6.5
    │   │   │   │   [build-dependencies]
    │   │   │   │   └── autocfg v1.1.0
    │   │   │   └── scopeguard v1.1.0
    │   │   │   [build-dependencies]
    │   │   │   └── autocfg v1.1.0
    │   │   └── crossbeam-utils v0.8.8 (*)
    │   ├── either v1.6.1
    │   └── rayon-core v1.9.3
    │       ├── crossbeam-channel v0.5.4
    │       │   ├── cfg-if v1.0.0
    │       │   └── crossbeam-utils v0.8.8 (*)
    │       ├── crossbeam-deque v0.8.1 (*)
    │       ├── crossbeam-utils v0.8.8 (*)
    │       └── num_cpus v1.13.1
    │   [build-dependencies]
    │   └── autocfg v1.1.0
    ├── regex v1.5.6
    │   └── regex-syntax v0.6.26
    ├── serde v1.0.137
    ├── serde_cbor v0.11.2
    │   ├── half v1.8.2
    │   └── serde v1.0.137
    ├── serde_derive v1.0.137 (proc-macro)
    │   ├── proc-macro2 v1.0.39 (*)
    │   ├── quote v1.0.18 (*)
    │   └── syn v1.0.95 (*)
    ├── serde_json v1.0.81
    │   ├── itoa v1.0.2
    │   ├── ryu v1.0.10
    │   └── serde v1.0.137
    ├── tinytemplate v1.2.1
    │   ├── serde v1.0.137
    │   └── serde_json v1.0.81 (*)
    └── walkdir v2.3.2
        ├── same-file v1.0.6
        │   └── winapi-util v0.1.5
        │       └── winapi v0.3.9
        ├── winapi v0.3.9
        └── winapi-util v0.1.5 (*)
Weibye commented 2 years ago

Which is to say: I'm not sure what is the course of action we can take here to solve this. Do we find something other than Criterion to use? Do we convince them to change their dependencies?

alice-i-cecile commented 2 years ago

criterion should be a dev-dependency, which would take it out of the tree for the purposes that @james7132 cares about (reducing Bevy's dependency bloat).

Edit: looks like it already is, so I'm going to close this out.