Skip to content

Add a lower bound check to unicode-table-generator output - #122013

Merged
bors merged 1 commit into
rust-lang:masterfrom
Swatinem:unicode-gen-fastpath
Apr 20, 2024
Merged

Add a lower bound check to unicode-table-generator output#122013
bors merged 1 commit into
rust-lang:masterfrom
Swatinem:unicode-gen-fastpath

Conversation

@Swatinem

Copy link
Copy Markdown
Contributor

This adds a dedicated check for the lower bound
(if it is outside of ASCII range) to the output of the unicode-table-generator tool.

This generalized the ASCII-only fast-path, but only for the Grapheme_Extend property for now, as that is the only one with a lower bound outside of ASCII.

@rustbot

Copy link
Copy Markdown
Collaborator

r? @scottmcm

rustbot has assigned @scottmcm.
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

@rustbotrustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 5, 2024
@Swatinem

Copy link
Copy Markdown
ContributorAuthor

As doing this only for the ASCII lower bound only applied to a single table, how about covering the full range? As in: (lower..upper).contains(c as u32) or something like that?

@workingjubilee

workingjubilee commented Mar 5, 2024

Copy link
Copy Markdown
Member

That doesn't sound like it would be faster, as it would be both a lower bound check and an upper bound check before moving on to the bitset search? Checking the lower bound seems good, but for the upper bound, I would assume letting the binary search play out would be faster.

writeln!(&mut self.file, "pub const fn lookup(c: char) -> bool {{").unwrap();
writeln!(&mut self.file, " super::bitset_search(",).unwrap();
if first_code_point > 0x7f {
writeln!(&mut self.file, " (c as u32) >= {first_code_point} &&").unwrap();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
writeln!(&mutself.file," (c as u32) >= {first_code_point} &&").unwrap();
writeln!(&mutself.file," (c as u32) >= {first_code_point:#04x} &&").unwrap();

Just to keep the hex consistent. Could also do u32::from(c) rather than the as cast since it has that impl, but makes no difference.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the other numbers in this file are printed as decimals, but I did this change. This might also solve the confusion in the other review comment.

Comment threadsrc/tools/unicode-table-generator/src/skiplist.rs Outdated
@tgross35

Copy link
Copy Markdown
Member

Honestly I think you may as well close #121138 before it merges in favor of this, otherwise you'll just have to undo it 😄

128, 240, 0,
];
pub fn lookup(c: char) -> bool {
(c as u32) >= 768 &&

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsure: I see in SHORT_OFFSET_RUNS that the first one is 768, which looks awfully similar to this 768. Should this be doing c as u32 - 768 and making each of the statics shorter?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven’t really spent much time figuring out how the skip list search actually works, and what the meaning of those entries is.
Looking at all the other tables, the first entry in SHORT_OFFSET_RUNS does not match the lower bound, so it might just be coincidence.

Maybe its possible to do a checked_sub and take advantage of this, but I would have to dig deeper into the code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair, can separate this improvement from any tweak to the tables.

@Swatinem
Swatinemforce-pushed the unicode-gen-fastpath branch 2 times, most recently from ad7b782 to 6d7daa0CompareMarch 5, 2024 19:25
@Swatinem

Copy link
Copy Markdown
ContributorAuthor

I ended up reverting #121138 in this PR as well, since this impl is more general than that.
Although I’m not entirely sure, since the lookup function does not have an #[inline] annotations, so I’m not sure if it will have the same perf impact.

@cuviper

Copy link
Copy Markdown
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbotrustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 8, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 8, 2024
Add a lower bound check to `unicode-table-generator` output
This adds a dedicated check for the lower bound
(if it is outside of ASCII range) to the output of the `unicode-table-generator` tool.
This generalized the ASCII-only fast-path, but only for the `Grapheme_Extend` property for now, as that is the only one with a lower bound outside of ASCII.
@bors

bors commented Mar 8, 2024

Copy link
Copy Markdown
Collaborator

⌛ Trying commit 6d7daa0 with merge 554f230...

@bors

bors commented Mar 8, 2024

Copy link
Copy Markdown
Collaborator

☀️ Try build successful - checks-actions
Build commit: 554f230 (554f2305f7f70bf404662f432d49f94ad0c72ec6)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (554f230): comparison URL.

Overall result: ✅ improvements - no action needed

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.

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

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

meanrangecount
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
-0.3%[-0.3%, -0.3%]1
All ❌✅ (primary)--0

Max RSS (memory usage)

Results

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.

meanrangecount
Regressions ❌
(primary)
5.8%[5.1%, 6.6%]2
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
-5.4%[-5.4%, -5.4%]1
All ❌✅ (primary)5.8%[5.1%, 6.6%]2

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 647.485s -> 647.691s (0.03%)
Artifact size: 172.63 MiB -> 172.63 MiB (0.00%)

@rustbotrustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 8, 2024
@Swatinem

Copy link
Copy Markdown
ContributorAuthor

The fmt-debug-derive Runtime benchmark reports a regression of 12.18%, so it seems like the #[inline] annotation is indeed significant 🤔

@scottmcm

Copy link
Copy Markdown
Member

Let's re-run perf to ensure that things are fine with the #[inline] still there.

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbotrustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 27, 2024
@bors

bors commented Mar 27, 2024

Copy link
Copy Markdown
Collaborator

⌛ Trying commit 6d7daa0 with merge fb17f9e...

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 27, 2024
Add a lower bound check to `unicode-table-generator` output
This adds a dedicated check for the lower bound
(if it is outside of ASCII range) to the output of the `unicode-table-generator` tool.
This generalized the ASCII-only fast-path, but only for the `Grapheme_Extend` property for now, as that is the only one with a lower bound outside of ASCII.
@bors

bors commented Mar 27, 2024

Copy link
Copy Markdown
Collaborator

☀️ Try build successful - checks-actions
Build commit: fb17f9e (fb17f9e4e044d2120c9a5a58f07bebaa24a1a93b)

@scottmcmscottmcm reopened this Apr 18, 2024
@scottmcm

Copy link
Copy Markdown
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@bors

bors commented Apr 18, 2024

Copy link
Copy Markdown
Collaborator

⌛ Trying commit 580c6a1 with merge 2746faf...

bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 18, 2024
Add a lower bound check to `unicode-table-generator` output
This adds a dedicated check for the lower bound
(if it is outside of ASCII range) to the output of the `unicode-table-generator` tool.
This generalized the ASCII-only fast-path, but only for the `Grapheme_Extend` property for now, as that is the only one with a lower bound outside of ASCII.
@bors

bors commented Apr 18, 2024

Copy link
Copy Markdown
Collaborator

☀️ Try build successful - checks-actions
Build commit: 2746faf (2746faf07f3279b425969d2ad1069c1f955af851)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (2746faf): comparison URL.

Overall result: ❌ regressions - no action needed

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.

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

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

meanrangecount
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
3.9%[3.9%, 3.9%]1
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
--0
All ❌✅ (primary)--0

Max RSS (memory usage)

Results

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.

meanrangecount
Regressions ❌
(primary)
8.7%[8.7%, 8.7%]1
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
-1.0%[-1.0%, -1.0%]1
Improvements ✅
(secondary)
--0
All ❌✅ (primary)3.9%[-1.0%, 8.7%]2

Cycles

Results

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.

meanrangecount
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
3.6%[3.6%, 3.6%]1
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
--0
All ❌✅ (primary)--0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 676.731s -> 676.644s (-0.01%)
Artifact size: 316.11 MiB -> 315.35 MiB (-0.24%)

@rustbotrustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 18, 2024

@scottmcmscottmcm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perf looks happy with the inline -- sorry it took weeks to actually get a run -- so I think this is nearly good to go. Just had a couple minor requests.

Comment threadlibrary/core/src/unicode/unicode_data.rs Outdated
Comment threadlibrary/core/src/unicode/unicode_data.rs Outdated
@rustbotrustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 18, 2024
This adds a dedicated check for the lower bound
(if it is outside of ASCII range) to the output of the `unicode-table-generator` tool.
This generalized the ASCII-only fast-path, but only for the `Grapheme_Extend` property for now,
as that is the only one with a lower bound outside of ASCII.
@Swatinem
Swatinemforce-pushed the unicode-gen-fastpath branch from 580c6a1 to 488598cCompareApril 20, 2024 08:17
@Swatinem

Copy link
Copy Markdown
ContributorAuthor

Rebased and applied the suggestions.

@Swatinem

Copy link
Copy Markdown
ContributorAuthor

@rustbot ready

@rustbotrustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 20, 2024
@scottmcm

Copy link
Copy Markdown
Member

Thanks!
@bors r+ rollup=iffy (should now be perf-neutral so I don't think it needs never)

This also has me curious what would happen if we added a lower-bound check outside the probably-not-inlined part for everything, but that's definitely not a this-PR kind of thing 🙃

@bors

bors commented Apr 20, 2024

Copy link
Copy Markdown
Collaborator

📌 Commit 488598c has been approved by scottmcm

It is now in the queue for this repository.

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 20, 2024
@bors

bors commented Apr 20, 2024

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 488598c with merge dbce3b4...

@bors

bors commented Apr 20, 2024

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-actions
Approved by: scottmcm
Pushing dbce3b4 to master...

@borsbors added the merged-by-bors This PR was explicitly merged by bors. label Apr 20, 2024
@bors
bors merged commit dbce3b4 into rust-lang:masterApr 20, 2024
@rustbotrustbot added this to the 1.79.0 milestone Apr 20, 2024
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (dbce3b4): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

meanrangecount
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
1.3%[1.3%, 1.3%]1
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
--0
All ❌✅ (primary)--0

Max RSS (memory usage)

Results

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.

meanrangecount
Regressions ❌
(primary)
4.4%[0.8%, 8.0%]2
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
--0
All ❌✅ (primary)4.4%[0.8%, 8.0%]2

Cycles

Results

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.

meanrangecount
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
-2.8%[-3.0%, -2.6%]2
All ❌✅ (primary)--0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 671.454s -> 673.418s (0.29%)
Artifact size: 315.20 MiB -> 315.27 MiB (0.02%)

@Swatinem
Swatinem deleted the unicode-gen-fastpath branch May 25, 2024 20:23
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-borsThis PR was explicitly merged by bors.S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-libsRelevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants

@Swatinem@rustbot@workingjubilee@tgross35@cuviper@rust-timer@bors@scottmcm@RalfJung