Skip to content

bcs: clean deps, reduce CI clean build time#14

Merged
ma2bd merged 3 commits intozefchain:mainfrom
phlip9:phlip9/clean-deps
Apr 1, 2026
Merged

bcs: clean deps, reduce CI clean build time#14
ma2bd merged 3 commits intozefchain:mainfrom
phlip9:phlip9/clean-deps

Conversation

@phlip9
Copy link
Copy Markdown
Contributor

@phlip9 phlip9 commented Mar 18, 2026

Changes

  • msrv: 1.56 -> 1.61
  • bcs: only depend on serde_core

Description

Hey!

I noticed bcs on the critical path of a build.rs script in CI, so I took a pass at fixing that. After some slight refactoring to (1) remove thiserror and (2) use serde_core traits directly, the "1 vCPU in CI" clean build time is down ~5.7x, without many downsides:

Before:

$ cargo tree --edges build,normal
bcs v0.1.6 (/home/phlip9/dev/bcs)
├── serde v1.0.228
│   ├── serde_core v1.0.228
│   └── serde_derive v1.0.228 (proc-macro)
│       ├── proc-macro2 v1.0.106
│       │   └── unicode-ident v1.0.24
│       ├── quote v1.0.45
│       │   └── proc-macro2 v1.0.106 (*)
│       └── syn v2.0.117
│           ├── proc-macro2 v1.0.106 (*)
│           ├── quote v1.0.45 (*)
│           └── unicode-ident v1.0.24
└── thiserror v1.0.69
    └── thiserror-impl v1.0.69 (proc-macro)
        ├── proc-macro2 v1.0.106 (*)
        ├── quote v1.0.45 (*)
        └── syn v2.0.117 (*)

$ rm -rf /tmp/cargo-target && taskset -c 3 cargo build --target-dir /tmp/cargo-target --lib
    Finished dev [unoptimized + debuginfo] target(s) in 7.89s

After:

$ cargo tree --edges build,normal
    Updating crates.io index
bcs v0.1.6 (/home/phlip9/dev/bcs)
└── serde_core v1.0.228

$ rm -rf /tmp/cargo-target && taskset -c 3 cargo build --target-dir /tmp/cargo-target --lib
   Compiling serde_core v1.0.228
   Compiling bcs v0.1.6 (/home/phlip9/dev/bcs)
    Finished dev [unoptimized + debuginfo] target(s) in 1.38s

`bcs` only uses proc-macro serde derives in tests. We can reduce compile
times by using `serde_core` directly, which only exports the core serde
traits.
@citizen-stig
Copy link
Copy Markdown

Would be nice to see it merged, but latest commit on main branch is 3 years ago...

@phlip9
Copy link
Copy Markdown
Contributor Author

phlip9 commented Mar 30, 2026

cc @ma2bd, you guys still using bcs at linera? any chance we could get this merged? thanks!

@ma2bd ma2bd requested review from bmwill and ma2bd March 30, 2026 17:45
@ma2bd
Copy link
Copy Markdown
Contributor

ma2bd commented Mar 30, 2026

Interesting. How much time was spent in thiserror? That's the one change that I find a little sad.

@bmwill what do you think?

@bmwill
Copy link
Copy Markdown

bmwill commented Mar 30, 2026

@phlip9 Its been a while!

Yeah i'd be supportive of a change like this. I think 100% of what we get from thiserror can be rather trivially implemented explicitly (and tools like claude made maintaining that not that much of a lift)

@citizen-stig
Copy link
Copy Markdown

Just to chime in, if you decide to keep thiserror, could we bump it to v2 + default_features=false ?

But Imho what @phlip9 did looks pretty good to me

@phlip9
Copy link
Copy Markdown
Contributor Author

phlip9 commented Mar 30, 2026

here's the cargo build --timings=html graph on main:

image
# 1-core cargo build w/ timings
$ rm -rf /tmp/cargo-target && taskset -c 1 env RUSTC_BOOTSTRAP=1 cargo build --target-dir /tmp/cargo-target --lib -Z unstable-options --timings=html

$ open /tmp/cargo-target/cargo-timings/cargo-timing-*.html

phlip9 added 2 commits March 30, 2026 12:54
Before:

```
$ cargo tree --edges build,normal
bcs v0.1.6 (/home/phlip9/dev/bcs)
├── serde v1.0.228
│   ├── serde_core v1.0.228
│   └── serde_derive v1.0.228 (proc-macro)
│       ├── proc-macro2 v1.0.106
│       │   └── unicode-ident v1.0.24
│       ├── quote v1.0.45
│       │   └── proc-macro2 v1.0.106 (*)
│       └── syn v2.0.117
│           ├── proc-macro2 v1.0.106 (*)
│           ├── quote v1.0.45 (*)
│           └── unicode-ident v1.0.24
└── thiserror v1.0.69
    └── thiserror-impl v1.0.69 (proc-macro)
        ├── proc-macro2 v1.0.106 (*)
        ├── quote v1.0.45 (*)
        └── syn v2.0.117 (*)

$ rm -rf /tmp/cargo-target && taskset -c 3 cargo build --target-dir /tmp/cargo-target --lib
    Finished dev [unoptimized + debuginfo] target(s) in 7.89s
```

After:

```
$ cargo tree --edges build,normal
    Updating crates.io index
bcs v0.1.6 (/home/phlip9/dev/bcs)
└── serde_core v1.0.228

$ rm -rf /tmp/cargo-target && taskset -c 3 cargo build --target-dir /tmp/cargo-target --lib
   Compiling serde_core v1.0.228
   Compiling bcs v0.1.6 (/home/phlip9/dev/bcs)
    Finished dev [unoptimized + debuginfo] target(s) in 1.38s
```
In theory we should be able to support an MSRV of `1.56`. Unfortunately this
entry in `serde_core`'s Cargo.toml seems to confuse Cargo into adding
`serde_derive` into the lock file, which only has a compatible MSRV of `1.61`.

```toml
[target.'cfg(any())'.dependencies]
serde_derive = { version = "=1.0.220", path = "../serde_derive" }
```
@phlip9 phlip9 force-pushed the phlip9/clean-deps branch from 4837312 to 6ca5804 Compare March 30, 2026 21:36
@phlip9
Copy link
Copy Markdown
Contributor Author

phlip9 commented Mar 30, 2026

Took the liberty of fixing up CI. Unfortunately due to some cargo dependency resolution quirks, I've had to raise the MSRV from 1.56 -> 1.61. In theory 1.56 should work. Unfortunately this entry in serde_core's Cargo.toml seems to confuse Cargo into adding serde_derive into the lock file, which only has a compatible MSRV of 1.61.

[target.'cfg(any())'.dependencies]
serde_derive = { version = "=1.0.220", path = "../serde_derive" }

I've also committed a working Cargo.lock, since letting cargo resolve the latest dependencies doesn't work for either 1.56 (MSRV) or 1.73 (pinned).

The rust-version -aware resolver is also completely useless... so the fixups need to be done manually:

$ cargo +nightly generate-lockfile -Z unstable-options -Z msrv-policy

$ cargo +nightly update getrandom@0.4.2 --precise 0.3.4
$ cargo +nightly update tempfile --precise 3.5.0
$ cargo +nightly update serde_json --precise 1.0.145
$ cargo +nightly update regex --precise 1.7.3
$ cargo +nightly update rayon --precise 1.6.1
$ cargo +nightly update rayon-core --precise 1.10.2
$ cargo +nightly update libc --precise 0.2.163
$ cargo +nightly update proc-macro2@1 --precise 1.0.103
$ cargo +nightly update syn@2 --precise 2.0.56
$ cargo +nightly update syn@2 --precise 2.0.81
$ cargo +nightly update ryu --precise 1.0.20
$ cargo +nightly update quote --precise 1.0.41
$ cargo +nightly update quote@1 --precise 1.0.41
$ cargo +nightly update either@1 --precise 1.13.0
$ cargo +nightly update unicode-ident@1 --precise 1.0.22
$ cargo +nightly update csv@1 --precise 1.3.0
$ cargo +nightly update unicode-width@0.1 --precise 0.1.8
$ cargo +nightly update plotters --precise 0.3.1
$ cargo +nightly update plotters-svg --precise 0.3.1
$ cargo +nightly update plotters-backend --precise 0.3.2
$ cargo +nightly update csv@1 --precise 1.1.6
$ cargo +nightly update csv-core --precise 0.1.10

@ma2bd
Copy link
Copy Markdown
Contributor

ma2bd commented Mar 30, 2026

Took the liberty of fixing up CI. Unfortunately due to some cargo dependency resolution quirks, I've had to raise the MSRV from 1.56 -> 1.61. In theory 1.56 should work. Unfortunately this entry in serde_core's Cargo.toml seems to confuse Cargo into adding serde_derive into the lock file, which only has a compatible MSRV of 1.61.

Thanks!

@citizen-stig
Copy link
Copy Markdown

It looks like you guys are getting closer to merge that!

@bmwill is there anything else important left that needs to be addressed?

Would it be possible to publish new version after this is merged?

@ma2bd ma2bd merged commit a419e00 into zefchain:main Apr 1, 2026
2 checks passed
@ma2bd
Copy link
Copy Markdown
Contributor

ma2bd commented Apr 1, 2026

@phlip9 This was published in version bcs 0.2.0

@phlip9 phlip9 deleted the phlip9/clean-deps branch April 1, 2026 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants