-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchI-compiletimeIssue: Problems and improvements with respect to compile times.Issue: Problems and improvements with respect to compile times.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
I've been playing around recently with compiling a crate that simply contains:
pub const BYTES: &[u8] = include_bytes!("large-binary-blob");
and I've been surprised that the compile time of this crate is pretty nontrivial!
For example this crate:
pub const BYTES: &[u8] = &[];
takes 0.060 seconds to compile on nightly for me. If a multi-megabyte binary (such as cargo
itself) is included:
pub const BYTES: &[u8] = include_bytes!("/path/to/.cargo/bin/cargo");
this crate takes 0.729 seconds to compile!
There appear to be at least two major sources of slowdown:
In the expansion ofinclude_bytes!
theexpr_lit
function callsfrom_lit_kind
which callsto_lit_token
that runs an operation per-byte, which is pretty expensive for multi-megabyte files.- Later in compilation while emitting metadata when we're processing constants we'll end up pretty printing them and pretty printing the byte string literal for a multi-megabyte file takes quite some time!
There may be a few other sources of slowdown, but ideally usage of include_bytes!
and large byte blobs in general should never iterate over the bytes and perform expensive operations, but rather the bytes should just be transferred as a whole in various contexts if absolutely necessary.
iwikal, crumblingstatue, Alexhuszagh, kennykerr, whentze and 14 more
Metadata
Metadata
Assignees
Labels
C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchI-compiletimeIssue: Problems and improvements with respect to compile times.Issue: Problems and improvements with respect to compile times.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.