Description
Proposal
Currently rustc will generate a no-op drop_in_place::<T>()
anytime a virtual table is constructed for a type that doesn't require drop (e.g., &u32
, u32
, etc.). This has several effects:
- The binary is larger (extra symbols, extra relocations)
- The virtual table may be forced to be non-constant, instead requiring relocation at load time to insert the resolved address.
This proposal replaces the pointer in such virtual tables with null. This does add a null check at runtime before calling the function, but that check should be fairly cheap at runtime and in terms of code size (essentially one extra branch). The wins appear to be worth it on our current set of benchmarks.
In practice this is a win on a number of perf.rlo benchmarks:
- librustc_driver.so shrinks by ~129 kb
- cargo shrinks by ~48 kb
- rustdoc shrinks by ~30 kb
- Total mean size improvement of 0.35%
See initial implementation here: rust-lang/rust#122662; needs some work to fix up cranelift/gcc most likely but should be mostly accurate in terms of gathering the above numbers. Opening this proposal to gather feedback on this approach before cleaning up the last bits of the PR.
Mentors or Reviewers
None yet.
Process
The main points of the Major Change Process are as follows:
- File an issue describing the proposal.
- A compiler team member or contributor who is knowledgeable in the area can second by writing
@rustbot second
.- Finding a "second" suffices for internal changes. If however, you are proposing a new public-facing feature, such as a
-C flag
, then full team check-off is required. - Compiler team members can initiate a check-off via
@rfcbot fcp merge
on either the MCP or the PR.
- Finding a "second" suffices for internal changes. If however, you are proposing a new public-facing feature, such as a
- Once an MCP is seconded, the Final Comment Period begins. If no objections are raised after 10 days, the MCP is considered approved.
You can read more about Major Change Proposals on forge.
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.