Skip to content

Faster Processor resets #776

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

Merged
merged 4 commits into from
Oct 17, 2024
Merged

Faster Processor resets #776

merged 4 commits into from
Oct 17, 2024

Conversation

milseman
Copy link
Member

Make processor reset faster by tracking dirty registers
and only clearing Arrays that are non-empty.

Built on top of #773

@milseman milseman requested a review from natecook1000 October 12, 2024 19:06
@milseman
Copy link
Member Author

rdar://137810309

@milseman milseman changed the title Faster resets Faster Processor resets Oct 12, 2024
Make processor reset faster by tracking dirty registers
and only clearing Arrays that are non-empty.
@milseman
Copy link
Member Author

Perf vs #773:

Comparing against saved benchmark result persist_state
=== Regressions ======================================================================
- EmailLookaheadList_Scalar               4.11ms	4.06ms	49.3µs		1.2%
- MACAddress_Scalar                       2.42ms	2.37ms	45.7µs		1.9%
- IPv6Address                             2.62ms	2.57ms	42.3µs		1.6%
=== Improvements =====================================================================
- CompilerMessages_All_Scalar             71ms	74.7ms	-3.68ms		-4.9%
- EmailRFCNoMatches_All                   48.9ms	51.9ms	-2.97ms		-5.7%
- EmailRFCNoMatches_All_Scalar            44.9ms	47.6ms	-2.69ms		-5.7%
- EmailLookaheadNoMatches_All             22.3ms	24.7ms	-2.38ms		-9.6%
- BasicRangeCCC_All_Scalar                4.04ms	6.36ms	-2.32ms		-36.5%
- BasicRangeCCC_All                       4.06ms	6.33ms	-2.27ms		-35.9%
- CaseInsensitiveCCC_All_Scalar           4.28ms	6.54ms	-2.26ms		-34.6%
- CaseInsensitiveCCC_All                  4.27ms	6.53ms	-2.26ms		-34.6%
- DiceRollsInText_All                     30.1ms	32.4ms	-2.25ms		-7.0%
- BasicCCC_All_Scalar                     3.91ms	6.11ms	-2.2ms		-36.0%
- DiceRollsInText_All_Scalar              28ms	30.1ms	-2.04ms		-6.8%
- BasicCCC_All                            3.93ms	5.89ms	-1.96ms		-33.3%
- NotFound_All                            4.82ms	6.61ms	-1.79ms		-27.1%
- LiteralSearchNotFound_All               3.93ms	5.56ms	-1.63ms		-29.3%
- EmailLookaheadNoMatches_All_Scalar      20.2ms	21.9ms	-1.63ms		-7.4%
- BasicBuiltinCharacterClass_All          4.03ms	5.66ms	-1.63ms		-28.7%
- SubtractionCCC_All_Scalar               6.31ms	7.93ms	-1.62ms		-20.4%
- IntersectionCCC_All                     5.95ms	7.56ms	-1.61ms		-21.3%
- IntersectionCCC_All_Scalar              5.99ms	7.58ms	-1.6ms		-21.1%
- SubtractionCCC_All                      6.31ms	7.9ms	-1.59ms		-20.1%
- LiteralSearch_All                       4.12ms	5.7ms	-1.58ms		-27.8%
- Numbers_All                             3.42ms	4.92ms	-1.5ms		-30.4%
- NotFound_All_Scalar                     3.71ms	5.2ms	-1.49ms		-28.7%
- LiteralSearch_All_Scalar                3.28ms	4.76ms	-1.48ms		-31.0%
- LiteralSearchNotFound_All_Scalar        3.15ms	4.6ms	-1.45ms		-31.5%
- symDiffCCC_All_Scalar                   18.1ms	19.5ms	-1.38ms		-7.1%
- symDiffCCC_All                          18.1ms	19.5ms	-1.36ms		-7.0%
- Numbers_All_Scalar                      2.63ms	3.96ms	-1.33ms		-33.6%
- HangulSyllable_All                      3.92ms	5.21ms	-1.29ms		-24.7%
- BasicBuiltinCharacterClass_All_Scalar   3.05ms	4.33ms	-1.28ms		-29.5%
- EmojiRegex_All                          125ms	126ms	-1.24ms		-1.0%
- HangulSyllable_All_Scalar               3.18ms	4.34ms	-1.15ms		-26.6%
- CompilerMessages_All                    90.1ms	91.2ms	-1.14ms		-1.2%
- EmailRFC_All                            32.8ms	33.8ms	-958µs		-2.8%
- EmojiRegex_All_Scalar                   43.7ms	44.7ms	-927µs		-2.1%
- HangulSyllable_First                    1.87ms	2.79ms	-919µs		-33.0%
- HangulSyllable_First_Scalar             1.49ms	2.24ms	-753µs		-33.6%
- EmailRFC_All_Scalar                     31.6ms	32.3ms	-698µs		-2.2%
- Words_All_Scalar                        5.2ms	5.84ms	-644µs		-11.0%
- Css_All_Scalar                          2.17ms	2.8ms	-636µs		-22.7%
- Words_All                               5.59ms	6.18ms	-591µs		-9.6%
- Css_All                                 2.55ms	3.11ms	-560µs		-18.0%
- InvertedCCC_All_Scalar                  6.79ms	7.21ms	-418µs		-5.8%
- InvertedCCC_All                         6.88ms	7.17ms	-295µs		-4.1%
- EmailLookahead_All_Scalar               17.7ms	18ms	-244µs		-1.4%
- URLWithWordBoundaries_All_SimpleWordBoundaries 674µs	900µs	-226µs		-25.1%
- ReluctantQuantWithTerminal_Whole        5.92ms	6.13ms	-215µs		-3.5%
- EmailBuiltinCharacterClass_All          9.21ms	9.41ms	-202µs		-2.1%
- URLWithWordBoundaries_All_Scalar        3.45ms	3.64ms	-195µs		-5.4%
- EmailLookahead_All                      20ms	20.2ms	-176µs		-0.9%
- EmailBuiltinCharacterClass_All_Scalar   8.97ms	9.13ms	-163µs		-1.8%
- AnchoredNotFound_First                  9.81ms	9.96ms	-152µs		-1.5%
- AnchoredNotFound_First_Scalar           5.91ms	6.05ms	-140µs		-2.3%
- ReluctantQuantWithTerminal_Whole_Scalar 5.92ms	6.04ms	-116µs		-1.9%
- ReluctantQuant_Whole                    9.84ms	9.93ms	-98.8µs		-1.0%
- Lines_All                               930µs	1.03ms	-95.5µs		-9.3%
- DiceNotation_Scalar                     4.55ms	4.64ms	-85.7µs		-1.8%
- Lines_All_Scalar                        888µs	957µs	-68.7µs		-7.2%
- GraphemeBreakNoCap_All                  1.78ms	1.84ms	-58.7µs		-3.2%
- AnchoredNotFound_All_Scalar             5.93ms	5.99ms	-54.9µs		-0.9%
- GraphemeBreakNoCap_All_Scalar           1.67ms	1.7ms	-29.1µs		-1.7%
- EagarQuantWithTerminal_Whole_Scalar     443µs	454µs	-10.8µs		-2.4%

@milseman
Copy link
Member Author

@swift-ci please test

@@ -128,6 +135,9 @@ extension Processor.Registers {
}

mutating func reset(sentinel: Input.Index) {
guard isDirty else {
return
}
Copy link
Member

Choose a reason for hiding this comment

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

Need to reset isDirty here, as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Shoot, let's see if that affects numbers...

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, you mean we can set isDirty = false outside of the guard statement? Right, that will actually be an improvement.

Copy link
Member Author

Choose a reason for hiding this comment

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

Doing that change doesn't affect correctness, just allows us to reset less often. This nets us 10-15% in the Hangul benchmarks! I'll include this improvement in an up-coming PR.

@milseman milseman merged commit a847713 into swiftlang:main Oct 17, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants