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

Nul terminate rust string literals #138504

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bjorn3
Copy link
Member

@bjorn3 bjorn3 commented Mar 14, 2025

This allows taking advantage of the C string merging functionality of linkers, reducing code size.

Marked as draft to see if this actually has much of an effect. The disadvantage of this is that people may start to rely on string literals getting nul terminated. A potential solution for that would be to put a byte that is not part of a valid UTF-8 character right before the nul terminator.

Builds on #138503

@rustbot
Copy link
Collaborator

rustbot commented Mar 14, 2025

r? @estebank

rustbot has assigned @estebank.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 14, 2025
@bjorn3
Copy link
Member Author

bjorn3 commented Mar 14, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 14, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 14, 2025
…r=<try>

Nul terminate rust string literals

This allows taking advantage of the C string merging functionality of linkers, reducing code size.

Marked as draft to see if this actually has much of an effect. The disadvantage of this is that people may start to rely on string literals getting nul terminated. A potential solution for that would be to put a byte that is not part of a valid UTF-8 character right before the nul terminator.

Builds on rust-lang#138503
@bors
Copy link
Contributor

bors commented Mar 14, 2025

⌛ Trying commit 7c1cd9b with merge f949c9f...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Mar 14, 2025

☀️ Try build successful - checks-actions
Build commit: f949c9f (f949c9f96faec0a24e98f55e36cfa88c14c2199c)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f949c9f): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.2% [0.3%, 1.8%] 5
Improvements ✅
(primary)
-1.2% [-4.3%, -0.3%] 12
Improvements ✅
(secondary)
-1.5% [-6.6%, -0.4%] 21
All ❌✅ (primary) -1.2% [-4.3%, -0.3%] 12

Max RSS (memory usage)

Results (primary 1.6%, secondary 2.0%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.2% [1.1%, 4.4%] 4
Regressions ❌
(secondary)
3.7% [1.9%, 4.8%] 3
Improvements ✅
(primary)
-1.2% [-1.2%, -1.2%] 1
Improvements ✅
(secondary)
-3.3% [-3.3%, -3.3%] 1
All ❌✅ (primary) 1.6% [-1.2%, 4.4%] 5

Cycles

Results (primary -2.3%, secondary -3.2%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.4% [2.3%, 2.6%] 2
Improvements ✅
(primary)
-2.3% [-3.8%, -1.2%] 3
Improvements ✅
(secondary)
-5.5% [-6.4%, -4.1%] 5
All ❌✅ (primary) -2.3% [-3.8%, -1.2%] 3

Binary size

Results (primary -0.5%, secondary -0.3%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.1% [0.0%, 0.1%] 8
Regressions ❌
(secondary)
0.0% [0.0%, 0.0%] 32
Improvements ✅
(primary)
-0.6% [-2.5%, -0.0%] 100
Improvements ✅
(secondary)
-0.5% [-3.0%, -0.0%] 43
All ❌✅ (primary) -0.5% [-2.5%, 0.1%] 108

Bootstrap: 775.364s -> 772.882s (-0.32%)
Artifact size: 365.01 MiB -> 365.44 MiB (0.12%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Mar 14, 2025
This way LLVM will set the string merging flag if the alloc is a nul
terminated string, reducing binary sizes.
@bjorn3 bjorn3 force-pushed the string_merging_rust_strings branch from 7c1cd9b to 827d66e Compare March 17, 2025 11:16
@rust-log-analyzer

This comment has been minimized.

This allows taking advantage of the C string merging functionality of
linkers, reducing code size.
@bjorn3 bjorn3 force-pushed the string_merging_rust_strings branch from 827d66e to d42a662 Compare March 17, 2025 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants