Skip to content

Measure binary size impact of implicit caller location #70579

Open
@anp

Description

@anp

The largest unanswered questions about implicit caller location are about the binary size impact of the feature and how to offer users control over it.

There are three ways I see that #[track_caller] inflates binaries:

  1. code bloat from panicking branches that were previously fused
  2. encoding the Location structs themselves
  3. encoding the &'static str for every filename referenced by a Location

We need to determine the impact to the ecosystem for each of these before deciding on mitigation strategy.

(1) was the main concern in the RFC but it was predicated on the assumption that #[track_caller] would affect inlining (an artifact of the implementation proposed). Since it doesn't affect inlining now, the only lost optimization in panicking branches would be for cases where LLVM previously used knowledge of a single constant panic location to make the failure path of a function smaller.

We've not yet had any reports of this and some ad-hoc measurements don't show any difference. This matches my mental model of LLVM's ability to optimize calling conventions which is "very expensive magic". I'm open to ideas for how to better assess this, including "wait and see".

TLDR Re (2) and (3),

Locations are 24 bytes when size_of::<usize>() == size_of::<u64>() and we don't currently measure how many we encode. We should put these in their own section to make it easier to measure.

Which filenames do we encode? In practice: probably all source files. We should put these in their own section too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchF-track_caller`#![feature(track_caller)]`I-heavyIssue: Problems and improvements with respect to binary size of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions