[core] Make SkSpan ctor checks debug-only

Commit daf82dad48 (Gerrit 1374256) turned the three SkASSERT checks in
SkSpan(T* ptr, Integer size) into SkASSERT_RELEASE. This slows down
SkParagraph layout by up to 21.6% in Flutter's Release+LTO
txt_benchmarks.

Under clang, SkASSERT_RELEASE puts the failure path in a lambda that is
called in place, and that call is not [[noreturn]]. ParagraphImpl::runs()
builds a span from TArray::size(), which is a signed int, so the
compiler cannot drop the SkTFitsIn and (ptr || size == 0) checks. In
our disassembly the extra cost stops LTO from inlining
TextStretch::startFrom and TextStretch::extend into
ParagraphImpl::layout, and the per-cluster loop in
TextWrapper::lookAhead then keeps its state on the stack instead of in
registers.

This change makes the three constructor checks SkASSERT again, as they
were before daf82dad48. The other release checks that daf82dad48 added
(SpanStorage and both subspan overloads) are unchanged. Debug builds
check the same conditions as before.

Ablation at daf82dad48 vs its parent 627b078141 (20 interleaved rounds,
pinned to 1 CPU core):
| Variant | LongLayout | TextBigO/1024 |
|---|---|---|
| daf82dad48 (3x SkASSERT_RELEASE) | +21.6% [+19.3, +24.2] | +10.6% [+8.2, +11.6] |
| any one SkASSERT_RELEASE kept | +14.7% .. +19.8% | -- |
| 3x SkASSERT (this change) | +0.0% [-1.7, +1.8] | -1.5% [-3.3, +1.3] |
| [[noreturn]] out-of-line failure call | -0.5% [-1.9, -0.1] | -0.7% [-3.8, +0.9] |

Before (HEAD 43b5507588) vs after (this change), 20 interleaved rounds
on CPU 47, median us, paired 95% bootstrap CI:
| Benchmark | Before | After | Delta [95% CI] |
|---|---:|---:|---|
| LongLayout | 20.48 | 16.56 | -20.1% [-20.9, -18.4] |
| TextBigO/1024 | 34.89 | 30.98 | -11.6% [-14.1, -8.6] |
| JustifyLayout | 46.97 | 42.55 | -9.7% [-12.7, -7.1] |
| ShortLayout | 0.984 | 0.910 | -7.8% [-9.8, -5.9] |

Not profiled: ARM64, MSVC, and non-LTO release builds. Host load
average was high (50 at start, 17 at end); A/B interleaving on one
pinned core keeps the paired ratios usable, the absolute numbers less so.

This lands first so that the next Skia roll does not bring the
regression into Flutter. Request to the author of daf82dad48: if these
checks must stay on in release builds, please bring them back without
SkASSERT_RELEASE's lambda, e.g. one non-template [[noreturn]]
out-of-line failure function (last row of the ablation table), and
measure txt_benchmarks before landing.

Bug: b/520529526
Perf: txt_benchmarks/LongLayout 20.48 -> 16.56 us (-20.1%, 95% CI [-20.9, -18.4], n=20/20) WIN
Perf: txt_benchmarks/TextBigO_1024 34.89 -> 30.98 us (-11.6%, 95% CI [-14.1, -8.6], n=20/20) WIN
Perf: txt_benchmarks/JustifyLayout 46.97 -> 42.55 us (-9.7%, 95% CI [-12.7, -7.1], n=20/20) WIN
Perf: txt_benchmarks/ShortLayout 0.984 -> 0.910 us (-7.8%, 95% CI [-9.8, -5.9], n=20/20) WIN
Assisted-by: Claude Opus 5.5 (Medium)
Change-Id: I9050ad77d0a34855875e7684b6b38d0c43b55075
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1414543
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Julia Lavrova <jlavrova@google.com>
1 file changed