Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip virtual drop for !needs_drop types #730

Closed
1 of 3 tasks
Mark-Simulacrum opened this issue Mar 18, 2024 · 3 comments
Closed
1 of 3 tasks

Skip virtual drop for !needs_drop types #730

Mark-Simulacrum opened this issue Mar 18, 2024 · 3 comments
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team

Comments

@Mark-Simulacrum
Copy link
Member

Mark-Simulacrum commented Mar 18, 2024

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.
  • 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.

@Mark-Simulacrum Mark-Simulacrum added T-compiler Add this label so rfcbot knows to poll the compiler team major-change A proposal to make a major change to rustc labels Mar 18, 2024
@rustbot
Copy link
Collaborator

rustbot commented Mar 18, 2024

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.

Concerns or objections to the proposal should be discussed on Zulip and formally registered here by adding a comment with the following syntax:

@rustbot concern reason-for-concern 
<description of the concern> 

Concerns can be lifted with:

@rustbot resolve reason-for-concern 

See documentation at https://forge.rust-lang.org

cc @rust-lang/compiler @rust-lang/compiler-contributors

@rustbot rustbot added the to-announce Announce this issue on triage meeting label Mar 18, 2024
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Apr 4, 2024
@pnkfelix
Copy link
Member

@rustbot second

@rustbot rustbot added the final-comment-period The FCP has started, most (if not all) team members are in agreement label Apr 18, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 27, 2024
Omit non-needs_drop drop_in_place in vtables

This replaces the drop_in_place reference with null in vtables. On librustc_driver.so, this drops about ~17k (11%) dynamic relocations from the output, since many vtables can now be placed in read-only memory, rather than having a relocated pointer included.

This makes a tradeoff by adding a null check at vtable call sites. I'm not sure that's readily avoidable without changing the vtable format (e.g., so that we can use a pc-relative relocation instead of an absolute address, and avoid the dynamic relocation that way). But it seems likely that the check is cheap at runtime.

Accepted MCP: rust-lang/compiler-team#730
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 27, 2024
Omit non-needs_drop drop_in_place in vtables

This replaces the drop_in_place reference with null in vtables. On librustc_driver.so, this drops about ~17k (11%) dynamic relocations from the output, since many vtables can now be placed in read-only memory, rather than having a relocated pointer included.

This makes a tradeoff by adding a null check at vtable call sites. I'm not sure that's readily avoidable without changing the vtable format (e.g., so that we can use a pc-relative relocation instead of an absolute address, and avoid the dynamic relocation that way). But it seems likely that the check is cheap at runtime.

Accepted MCP: rust-lang/compiler-team#730
bors added a commit to rust-lang-ci/rust that referenced this issue May 2, 2024
…-obk,bjorn3

Omit non-needs_drop drop_in_place in vtables

This replaces the drop_in_place reference with null in vtables. On librustc_driver.so, this drops about ~17k (11%) dynamic relocations from the output, since many vtables can now be placed in read-only memory, rather than having a relocated pointer included.

This makes a tradeoff by adding a null check at vtable call sites. I'm not sure that's readily avoidable without changing the vtable format (e.g., so that we can use a pc-relative relocation instead of an absolute address, and avoid the dynamic relocation that way). But it seems likely that the check is cheap at runtime.

Accepted MCP: rust-lang/compiler-team#730
bors added a commit to rust-lang-ci/rust that referenced this issue May 3, 2024
…-obk,bjorn3

Omit non-needs_drop drop_in_place in vtables

This replaces the drop_in_place reference with null in vtables. On librustc_driver.so, this drops about ~17k (11%) dynamic relocations from the output, since many vtables can now be placed in read-only memory, rather than having a relocated pointer included.

This makes a tradeoff by adding a null check at vtable call sites. I'm not sure that's readily avoidable without changing the vtable format (e.g., so that we can use a pc-relative relocation instead of an absolute address, and avoid the dynamic relocation that way). But it seems likely that the check is cheap at runtime.

Accepted MCP: rust-lang/compiler-team#730
bors added a commit to rust-lang-ci/rust that referenced this issue May 4, 2024
…-obk,bjorn3

Omit non-needs_drop drop_in_place in vtables

This replaces the drop_in_place reference with null in vtables. On librustc_driver.so, this drops about ~17k (11%) dynamic relocations from the output, since many vtables can now be placed in read-only memory, rather than having a relocated pointer included.

This makes a tradeoff by adding a null check at vtable call sites. I'm not sure that's readily avoidable without changing the vtable format (e.g., so that we can use a pc-relative relocation instead of an absolute address, and avoid the dynamic relocation that way). But it seems likely that the check is cheap at runtime.

Accepted MCP: rust-lang/compiler-team#730
bors added a commit to rust-lang-ci/rust that referenced this issue May 5, 2024
…-obk,bjorn3

Omit non-needs_drop drop_in_place in vtables

This replaces the drop_in_place reference with null in vtables. On librustc_driver.so, this drops about ~17k (11%) dynamic relocations from the output, since many vtables can now be placed in read-only memory, rather than having a relocated pointer included.

This makes a tradeoff by adding a null check at vtable call sites. I'm not sure that's readily avoidable without changing the vtable format (e.g., so that we can use a pc-relative relocation instead of an absolute address, and avoid the dynamic relocation that way). But it seems likely that the check is cheap at runtime.

Accepted MCP: rust-lang/compiler-team#730
bors added a commit to rust-lang-ci/rust that referenced this issue May 5, 2024
…-obk,bjorn3

Omit non-needs_drop drop_in_place in vtables

This replaces the drop_in_place reference with null in vtables. On librustc_driver.so, this drops about ~17k (11%) dynamic relocations from the output, since many vtables can now be placed in read-only memory, rather than having a relocated pointer included.

This makes a tradeoff by adding a null check at vtable call sites. I'm not sure that's readily avoidable without changing the vtable format (e.g., so that we can use a pc-relative relocation instead of an absolute address, and avoid the dynamic relocation that way). But it seems likely that the check is cheap at runtime.

Accepted MCP: rust-lang/compiler-team#730
@apiraino
Copy link
Contributor

@rustbot label -final-comment-period +major-change-accepted

@rustbot rustbot added major-change-accepted A major change proposal that was accepted to-announce Announce this issue on triage meeting and removed final-comment-period The FCP has started, most (if not all) team members are in agreement labels May 25, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue May 28, 2024
Omit non-needs_drop drop_in_place in vtables

This replaces the drop_in_place reference with null in vtables. On librustc_driver.so, this drops about ~17k (11%) dynamic relocations from the output, since many vtables can now be placed in read-only memory, rather than having a relocated pointer included.

This makes a tradeoff by adding a null check at vtable call sites. I'm not sure that's readily avoidable without changing the vtable format (e.g., so that we can use a pc-relative relocation instead of an absolute address, and avoid the dynamic relocation that way). But it seems likely that the check is cheap at runtime.

Accepted MCP: rust-lang/compiler-team#730
github-actions bot pushed a commit to rust-lang/miri that referenced this issue May 30, 2024
Omit non-needs_drop drop_in_place in vtables

This replaces the drop_in_place reference with null in vtables. On librustc_driver.so, this drops about ~17k (11%) dynamic relocations from the output, since many vtables can now be placed in read-only memory, rather than having a relocated pointer included.

This makes a tradeoff by adding a null check at vtable call sites. I'm not sure that's readily avoidable without changing the vtable format (e.g., so that we can use a pc-relative relocation instead of an absolute address, and avoid the dynamic relocation that way). But it seems likely that the check is cheap at runtime.

Accepted MCP: rust-lang/compiler-team#730
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Jun 7, 2024
flip1995 pushed a commit to flip1995/rust-clippy that referenced this issue Jun 28, 2024
Omit non-needs_drop drop_in_place in vtables

This replaces the drop_in_place reference with null in vtables. On librustc_driver.so, this drops about ~17k (11%) dynamic relocations from the output, since many vtables can now be placed in read-only memory, rather than having a relocated pointer included.

This makes a tradeoff by adding a null check at vtable call sites. I'm not sure that's readily avoidable without changing the vtable format (e.g., so that we can use a pc-relative relocation instead of an absolute address, and avoid the dynamic relocation that way). But it seems likely that the check is cheap at runtime.

Accepted MCP: rust-lang/compiler-team#730
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team
Projects
None yet
Development

No branches or pull requests

4 participants