ref: reimplement uuid init without string subscript extensions
I noticed this at first by discovering the tests for the string subscripts.
First, I think subscripts are generally bad to use as a custom extension, because discoverability is nonexistent. You can't ⌘ click on them to jump to their def. You can't ⌘ O to quick open to them.
Second, we never even had a test for the one thing they were being used for: creating a UUID from a string. (I added such a test)
Third, they were used in one spot. I rewrote that spot to use a reduce. It turns out to be faster, almost twice as fast:
before:
relative standard deviation: 147.699%, values: [0.000473, 0.000064, 0.000047, 0.000044, 0.000042, 0.000041, 0.000041, 0.000040, 0.000040, 0.000040]
after:
relative standard deviation: 179.733%, values: [0.000387, 0.000036, 0.000027, 0.000024, 0.000023, 0.000023, 0.000022, 0.000022, 0.000021, 0.000021]
#skip-changelog
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 91.380%. Comparing base (
0f4071f) to head (11e5d06). Report is 2 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #4133 +/- ##
=============================================
- Coverage 91.387% 91.380% -0.008%
=============================================
Files 606 605 -1
Lines 48301 48260 -41
Branches 17434 17396 -38
=============================================
- Hits 44141 44100 -41
Misses 4067 4067
Partials 93 93
| Files | Coverage Δ | |
|---|---|---|
| Sources/Swift/Extensions/StringExtensions.swift | 100.000% <ø> (ø) |
|
| Sources/Swift/Protocol/SentryId.swift | 100.000% <100.000%> (ø) |
|
| Tests/SentryTests/Protocol/SentryIdTests.swift | 100.000% <100.000%> (ø) |
... and 3 files with indirect coverage changes
Continue to review full report in Codecov by Sentry.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 0f4071f...11e5d06. Read the comment docs.
Performance metrics :rocket:
| Plain | With Sentry | Diff | |
|---|---|---|---|
| Startup time | 1223.04 ms | 1235.63 ms | 12.59 ms |
| Size | 21.58 KiB | 682.20 KiB | 660.62 KiB |
Baseline results on branch: main
Startup times
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 98a8c16494c5fb68f2218a5635a2443961ce7749 | 1234.69 ms | 1265.02 ms | 30.33 ms |
| 8e76be4558a9e15fe63841bbb98faec7d921f24e | 1272.67 ms | 1286.38 ms | 13.71 ms |
| 591a01b3e320697e7cc86082284d786c359306e3 | 1197.94 ms | 1222.53 ms | 24.59 ms |
| 5cabf7ed4789ca11913d7c24b6f8d9b66578cd26 | 1247.12 ms | 1249.61 ms | 2.49 ms |
| b9a9ffd9ab91b555e7b798a60311876a15b87b01 | 1221.18 ms | 1235.37 ms | 14.19 ms |
| c291fcc0ff35822d65951cf8c202a99bc129c7eb | 1204.60 ms | 1226.59 ms | 21.99 ms |
| dacf894bd3ce125f76ea565dbc543db3da8bf94d | 1223.96 ms | 1250.41 ms | 26.45 ms |
| 7bc3c0d8e54a5921c8c1a9510088c683dba2c1b2 | 1261.16 ms | 1278.38 ms | 17.22 ms |
| dd0557fb0fec40f5527e4f40ead6f82e092fde0f | 1246.31 ms | 1258.46 ms | 12.15 ms |
| ff5c1d83bf601bbcd0f5f1070c3abf05310881bd | 1236.67 ms | 1252.34 ms | 15.67 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 98a8c16494c5fb68f2218a5635a2443961ce7749 | 20.76 KiB | 431.00 KiB | 410.24 KiB |
| 8e76be4558a9e15fe63841bbb98faec7d921f24e | 20.76 KiB | 427.66 KiB | 406.89 KiB |
| 591a01b3e320697e7cc86082284d786c359306e3 | 22.84 KiB | 401.67 KiB | 378.83 KiB |
| 5cabf7ed4789ca11913d7c24b6f8d9b66578cd26 | 20.76 KiB | 419.67 KiB | 398.91 KiB |
| b9a9ffd9ab91b555e7b798a60311876a15b87b01 | 21.58 KiB | 418.43 KiB | 396.85 KiB |
| c291fcc0ff35822d65951cf8c202a99bc129c7eb | 21.58 KiB | 669.82 KiB | 648.24 KiB |
| dacf894bd3ce125f76ea565dbc543db3da8bf94d | 20.76 KiB | 426.34 KiB | 405.58 KiB |
| 7bc3c0d8e54a5921c8c1a9510088c683dba2c1b2 | 20.76 KiB | 427.36 KiB | 406.59 KiB |
| dd0557fb0fec40f5527e4f40ead6f82e092fde0f | 22.85 KiB | 411.75 KiB | 388.90 KiB |
| ff5c1d83bf601bbcd0f5f1070c3abf05310881bd | 20.76 KiB | 430.98 KiB | 410.22 KiB |
Previous results on branch: armcknight/ref/remove-swift-string-subscript-extensions
Startup times
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 5b664d26b6ae4784c8ce1eaaf286418183781e10 | 1222.96 ms | 1242.90 ms | 19.94 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 5b664d26b6ae4784c8ce1eaaf286418183781e10 | 21.58 KiB | 678.23 KiB | 656.65 KiB |
First, I think subscripts are generally bad to use as a custom extension, because discoverability is nonexistent. You can't ⌘ click on them to jump to their def. You can't ⌘ O to quick open to them.
This is a matter of culture building. After we get used to it, there will be no doubt about how it works. It's also not possible to "⌘ O" the original string subscript, and that is not a problem.
This particular extension is very useful.
But, I don't mind changing this piece of code. If it works, it works.
This is a matter of culture building
Absolutely. I'm trying to build a culture that results in a codebase that is simpler to understand and maintain. Swift is a very flexible language, and thus it's very easy to create an incomprehensible mess of code. I've watched people do it over and over again. This lesson should have been learned with C++ operator overloading, but here we are. "...so preoccupied with whether or not they could that they didn't stop to think if they should..." and I'm saying we shouldn't.
It's also not possible to "⌘ O" the original string subscript, and that is not a problem
This is a matter of opinion. In my opinion, it is a problem. In my opinion, Swift's substring APIs are horrible. Have fun writing a regex to grep through a codebase for a usage of a subscript, but only the one used for a substring access. It would be much easier to grep for .substring(from:to:).