Skip to content

Conversation

@xwu
Copy link
Collaborator

@xwu xwu commented Nov 9, 2025

A follow-up to #85180.

First, make the guarantee that our Swift-native implementation of integer-to-ASCII conversion always fills the suffix of the given mutable span.

(Some minor swift-format corrections interspersed.)

Then, use that guarantee to work in 64-bit chunks for larger integers—currently limited to decimal printing with a hardcoded divisor for chunking.

@xwu xwu requested a review from a team as a code owner November 9, 2025 23:08
@xwu
Copy link
Collaborator Author

xwu commented Nov 9, 2025

@swift-ci please benchmark

@xwu
Copy link
Collaborator Author

xwu commented Nov 10, 2025

4-5x improvement in UInt128 decimal printing benchmark

Performance (x86_64): -O

Regression OLD NEW DELTA RATIO
EqualSubstringString 22.0 30.051 +36.6% 0.73x (?)
LessSubstringSubstring 23.686 30.156 +27.3% 0.79x (?)
LessSubstringSubstringGenericComparable 23.688 30.154 +27.3% 0.79x (?)
EqualStringSubstring 23.633 30.04 +27.1% 0.79x (?)
EqualSubstringSubstringGenericEquatable 24.586 30.36 +23.5% 0.81x (?)
EqualSubstringSubstring 24.594 30.36 +23.4% 0.81x (?)
UTF8Decode_InitDecoding 135.769 167.0 +23.0% 0.81x (?)
Data.hash.Medium 30.433 37.227 +22.3% 0.82x (?)
SubstringEqualString 130.929 159.5 +21.8% 0.82x (?)
UTF8Decode_InitFromCustom_contiguous 137.769 167.364 +21.5% 0.82x (?)
UTF8Decode_InitFromData 141.615 171.182 +20.9% 0.83x (?)
UTF8Decode_InitFromBytes 158.182 190.1 +20.2% 0.83x (?)
UTF8Decode_InitFromCustom_noncontiguous 165.273 196.4 +18.8% 0.84x (?)
StringComparison_longSharedPrefix 208.3 238.2 +14.4% 0.87x (?)
SubstringEquatable 274.857 311.0 +13.1% 0.88x (?)
NormalizedIterator_fastPrenormal 489.4 551.154 +12.6% 0.89x (?)
StringDistance.characters.ascii 914.0 1017.5 +11.3% 0.90x (?)
FindString.Loop1.Substring 213.545 235.0 +10.0% 0.91x (?)
StringHasSuffixUnicode 47954.545 51956.522 +8.3% 0.92x (?)
SortStringsUnicode 2100.0 2272.5 +8.2% 0.92x (?)
 
Improvement OLD NEW DELTA RATIO
NSString.bridged.byteCount.ascii.utf16 0.5 0.0 -99.8% 501.00x (?)
IntegerToString.UInt128.decimal 152.778 29.545 -80.7% 5.17x
Breadcrumbs.CopyAllUTF16CodeUnits.longMixed 200.5 149.813 -25.3% 1.34x (?)
Breadcrumbs.CopyAllUTF16CodeUnits.Mixed 202.1 151.8 -24.9% 1.33x (?)
Breadcrumbs.CopyUTF16CodeUnits.longMixed 205.727 155.6 -24.4% 1.32x (?)
Calculator 169.273 148.455 -12.3% 1.14x (?)
StringComparison_ascii 224.556 198.7 -11.5% 1.13x (?)
StringSwitch 304.0 270.833 -10.9% 1.12x (?)
NormalizedIterator_ascii 77.5 70.222 -9.4% 1.10x (?)
StringHashing_nonBMPSlowestPrenormal 335.849 305.814 -8.9% 1.10x (?)
SortStrings 522.25 476.25 -8.8% 1.10x (?)
StringHashing_slowerPrenormal 243.226 221.846 -8.8% 1.10x (?)
Chars2 3347.619 3056.522 -8.7% 1.10x (?)
NSString.bridged.byteCount.utf8.utf16 1.393 1.273 -8.6% 1.09x (?)
ObjectiveCBridgeStringHash 62.333 57.324 -8.0% 1.09x (?)
String.replaceSubrange.Substring 11.104 10.245 -7.7% 1.08x (?)
StringHashing_zalgo 2316.667 2138.235 -7.7% 1.08x (?)
StringHashing_emoji 259.467 239.5 -7.7% 1.08x (?)
StringWordBuilder 1247.857 1152.143 -7.7% 1.08x (?)
StringComparison_zalgo 40100.0 37375.0 -6.8% 1.07x (?)

Code size: -O

Performance (x86_64): -Osize

Regression OLD NEW DELTA RATIO
EqualSubstringSubstringGenericEquatable 23.44 30.527 +30.2% 0.77x (?)
EqualSubstringSubstring 23.438 30.516 +30.2% 0.77x
EqualStringSubstring 23.733 30.152 +27.0% 0.79x (?)
EqualSubstringString 23.727 30.038 +26.6% 0.79x (?)
Data.hash.Medium 30.448 37.885 +24.4% 0.80x (?)
UTF8Decode_InitFromCustom_contiguous 135.538 167.909 +23.9% 0.81x (?)
UTF8Decode_InitFromBytes 156.538 193.333 +23.5% 0.81x (?)
UTF8Decode_InitFromData 138.538 171.0 +23.4% 0.81x (?)
LessSubstringSubstringGenericComparable 24.971 30.703 +23.0% 0.81x (?)
LessSubstringSubstring 24.97 30.7 +22.9% 0.81x (?)
SubstringEqualString 131.071 159.917 +22.0% 0.82x
UTF8Decode_InitDecoding 137.462 166.9 +21.4% 0.82x (?)
UTF8Decode_InitFromCustom_noncontiguous 217.0 259.5 +19.6% 0.84x (?)
SubstringEquatable 263.857 300.143 +13.8% 0.88x (?)
StringComparison_longSharedPrefix 216.364 245.4 +13.4% 0.88x (?)
FindString.Loop1.Substring 204.875 228.6 +11.6% 0.90x (?)
StringDistance.characters.ascii 913.0 1012.5 +10.9% 0.90x (?)
StringComparison_latin1 304.625 332.429 +9.1% 0.92x (?)
StringHasSuffixUnicode 47833.333 52041.667 +8.8% 0.92x (?)
SortStringsUnicode 2120.0 2280.0 +7.5% 0.93x (?)
CStringLongNonAscii 137.846 148.231 +7.5% 0.93x (?)
 
Improvement OLD NEW DELTA RATIO
NSString.bridged.byteCount.ascii.utf16 0.544 0.0 -99.8% 545.00x (?)
IntegerToString.UInt128.decimal 152.556 29.588 -80.6% 5.16x
Breadcrumbs.CopyAllUTF16CodeUnits.longMixed 200.545 150.938 -24.7% 1.33x
Breadcrumbs.CopyAllUTF16CodeUnits.Mixed 202.167 152.714 -24.5% 1.32x (?)
Breadcrumbs.CopyUTF16CodeUnits.longMixed 205.818 156.0 -24.2% 1.32x
StringHashing_nonBMPSlowestPrenormal 336.415 306.364 -8.9% 1.10x (?)
SortStrings 516.0 470.0 -8.9% 1.10x (?)
StringHashing_slowerPrenormal 243.478 222.245 -8.7% 1.10x (?)
String.replaceSubrange.Substring 11.11 10.235 -7.9% 1.09x (?)
StringHashing_emoji 260.138 240.25 -7.6% 1.08x (?)
StringHashing_zalgo 2314.286 2145.0 -7.3% 1.08x (?)
StringWordBuilder 1243.571 1152.667 -7.3% 1.08x (?)
StringSwitch 293.857 272.571 -7.2% 1.08x (?)
Chars2 4023.684 3733.333 -7.2% 1.08x (?)
StringWordBuilderReservingCapacity 1195.0 1116.0 -6.6% 1.07x (?)
CSVParsing.UTF16 48.0 44.848 -6.6% 1.07x (?)

Code size: -Osize

Performance (x86_64): -Onone

Regression OLD NEW DELTA RATIO
LessSubstringSubstring 25.594 34.188 +33.6% 0.75x (?)
EqualSubstringSubstring 25.375 33.458 +31.9% 0.76x (?)
LessSubstringSubstringGenericComparable 25.067 33.049 +31.8% 0.76x (?)
EqualSubstringSubstringGenericEquatable 25.706 33.548 +30.5% 0.77x (?)
EqualStringSubstring 26.783 34.5 +28.8% 0.78x (?)
EqualSubstringString 27.4 34.731 +26.8% 0.79x (?)
UTF8Decode_InitFromCustom_contiguous 146.25 181.6 +24.2% 0.81x (?)
UTF8Decode_InitFromData 142.667 172.444 +20.9% 0.83x (?)
UTF8Decode_InitDecoding 148.5 179.0 +20.5% 0.83x (?)
UTF8Decode_InitFromBytes 161.818 193.5 +19.6% 0.84x (?)
Data.hash.Medium 34.607 41.0 +18.5% 0.84x (?)
StringHasSuffixUnicode 49869.565 54500.0 +9.3% 0.92x (?)
CharacterRecognizer.ascii 171.167 184.455 +7.8% 0.93x (?)
CharIteration_japanese_unicodeScalars_Backwards 175720.0 189040.0 +7.6% 0.93x (?)
 
Improvement OLD NEW DELTA RATIO
IntegerToString.UInt128.decimal 164.444 41.563 -74.7% 3.96x
Breadcrumbs.CopyAllUTF16CodeUnits.longMixed 201.083 150.313 -25.2% 1.34x (?)
Breadcrumbs.CopyUTF16CodeUnits.longMixed 214.818 164.071 -23.6% 1.31x (?)
Breadcrumbs.CopyAllUTF16CodeUnits.Mixed 218.1 168.0 -23.0% 1.30x (?)
StringWithCString2 0.007 0.006 -12.5% 1.14x (?)
String.replaceSubrange.Substring 11.977 11.0 -8.2% 1.09x (?)
ObjectiveCBridgeStringHash 62.483 57.438 -8.1% 1.09x (?)

Code size: -swiftlibs

How to read the data The tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.

If you see any unexpected regressions, you should consider fixing the
regressions before you merge the PR.

Noise: Sometimes the performance results (not code size!) contain false
alarms. Unexpected regressions which are marked with '(?)' are probably noise.
If you see regressions which you cannot explain you can try to run the
benchmarks again. If regressions still show up, please consult with the
performance team (@eeckstein).

Hardware Overview
  Model Name: Mac mini
  Model Identifier: Macmini8,1
  Processor Name: 6-Core Intel Core i7
  Processor Speed: 3.2 GHz
  Number of Processors: 1
  Total Number of Cores: 6
  L2 Cache (per Core): 256 KB
  L3 Cache: 12 MB
  Memory: 32 GB

@xwu
Copy link
Collaborator Author

xwu commented Nov 10, 2025

@swift-ci smoke test

@xwu xwu marked this pull request as draft November 10, 2025 03:44
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.

1 participant