Skip to content

Recover the first-call compile time that #1128 added to sprand and widelength - #1137

Merged
ViralBShah merged 1 commit into
mainfrom
vs/widelength-ttfx
Oct 27, 2026
Merged

ViralBShah merged 1 commit into
mainfrom
vs/widelength-ttfx

Conversation

@ViralBShah

Copy link
Copy Markdown
Member

The TTFX check on #1136 flags the 1.14 backports: the cold run of sprand(200, 200, 0.05); kron(S, S); S * rand(200) went from 633 to 687 ms and the warm one from 274 to 289 ms. All of it comes from #1128. That PR raised the methods compiled by this workload from 465 to 514, and none of the other 28 backports changed it measurably.

Before (main)

julia> sprand(Xoshiro(1), 2^62, 4, 1e-17)
4611686018427387904×4 SparseMatrixCSC{Float64, Int64} with 169 stored entries

After

julia> sprand(Xoshiro(1), 2^62, 4, 1e-17)
ERROR: OverflowError: a 4611686018427387904×4 sparse matrix has more entries than `sprand` can draw from

First run of the TTFX workload in a fresh process, median of 16 runs interleaved, Julia 1.15.0-DEV.142 on macOS arm64. A cold run starts with an empty JIT object cache, as the check does:

cold run warm run methods compiled
before #1128 (4c87861) 282.8 ms 116.3 ms 465
main 302.0 ms 121.6 ms 514
this PR 282.9 ms 116.2 ms 450

widelength(x) = prod(widen, size(x)) went through mapreduce, MappingRF and ComposedFunction, about 35 methods on the first call of kron, sprand or a broadcast. It is now *(map(widen, size(x))...): the same Int128 product, from one call to *. sizehint! converts that bound to Int, which Base's sizehint! does anyway, so it is not compiled again for an Int128 size. Inference and codegen of sprand covered the branch that draws column by column for a matrix of 2^63 or more entries, even though no realistic call takes it. That branch is removed: sprand throws an OverflowError for such a size. Before #1128 it returned a matrix with no stored entries.

Should be backported to 1.14 so that #1136 picks it up.

Written by Claude Code.

🤖 Generated with Claude Code

…`widelength`

`widelength` is a product of the widened dimensions without `prod`'s
reduction machinery, `sizehint!` passes Base an `Int`, and `sprand` throws an
`OverflowError` for 2^63 or more entries instead of drawing column by column.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ViralBShah
ViralBShah enabled auto-merge (squash) October 27, 2026 04:47
@ViralBShah ViralBShah mentioned this pull request Oct 27, 2026
30 tasks done
@codecov

codecov Bot commented Oct 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.67%. Comparing base (3d92185) to head (b67117e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1137      +/-   ##
==========================================
+ Coverage   94.66%   94.67%   +0.01%     
==========================================
  Files          16       16              
  Lines       10437    10422      -15     
==========================================
- Hits         9880     9867      -13     
+ Misses        557      555       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ViralBShah
ViralBShah merged commit 9bfad27 into main Oct 27, 2026
12 checks passed
@ViralBShah
ViralBShah deleted the vs/widelength-ttfx branch October 27, 2026 04:49
ViralBShah added a commit that referenced this pull request Oct 27, 2026
…`widelength` (#1137)

The TTFX check on #1136 flags the 1.14 backports: the cold run of
`sprand(200, 200, 0.05); kron(S, S); S * rand(200)` went from 633 to 687
ms and the warm one from 274 to 289 ms. All of it comes from #1128. That
PR raised the methods compiled by this workload from 465 to 514, and
none of the other 28 backports changed it measurably.

**Before** (`main`)
```julia
julia> sprand(Xoshiro(1), 2^62, 4, 1e-17)
4611686018427387904×4 SparseMatrixCSC{Float64, Int64} with 169 stored entries
```

**After**
```julia
julia> sprand(Xoshiro(1), 2^62, 4, 1e-17)
ERROR: OverflowError: a 4611686018427387904×4 sparse matrix has more entries than `sprand` can draw from
```

First run of the TTFX workload in a fresh process, median of 16 runs
interleaved, Julia 1.15.0-DEV.142 on macOS arm64. A cold run starts with
an empty JIT object cache, as the check does:

| | cold run | warm run | methods compiled |
|---|---|---|---|
| before #1128 (4c87861) | 282.8 ms | 116.3 ms | 465 |
| `main` | 302.0 ms | 121.6 ms | 514 |
| this PR | 282.9 ms | 116.2 ms | 450 |

`widelength(x) = prod(widen, size(x))` went through `mapreduce`,
`MappingRF` and `ComposedFunction`, about 35 methods on the first call
of `kron`, `sprand` or a broadcast. It is now `*(map(widen,
size(x))...)`: the same `Int128` product, from one call to `*`.
`sizehint!` converts that bound to `Int`, which Base's `sizehint!` does
anyway, so it is not compiled again for an `Int128` size. Inference and
codegen of `sprand` covered the branch that draws column by column for a
matrix of 2^63 or more entries, even though no realistic call takes it.
That branch is removed: `sprand` throws an `OverflowError` for such a
size. Before #1128 it returned a matrix with no stored entries.

Should be backported to 1.14 so that #1136 picks it up.

Written by Claude Code.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Viral B. Shah <ViralBShah@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 9bfad27)
ViralBShah added a commit that referenced this pull request Oct 27, 2026
Backports of the merged PRs labelled `backport 1.14`, cherry-picked with
`-x` in the order they were merged on `main`. `release-1.14` starts at
b0aa455 (#1104), the commit JuliaLang/julia's `release-1.14` pins, and
every PR merged on `main` since then is labelled, so this branch's tree
is identical to `main`'s at 9bfad27.

- [x] #1105
- [x] #1011
- [x] #1107
- [x] #1108
- [x] #1110
- [x] #1111
- [x] #1114
- [x] #1112
- [x] #1115
- [x] #1117
- [x] #1118
- [x] #1109
- [x] #1113
- [x] #1122
- [x] #1123
- [x] #1120
- [x] #1124
- [x] #1125
- [x] #1116
- [x] #1121
- [x] #1126
- [x] #1128
- [x] #1130
- [x] #1131
- [x] #1119
- [x] #1133
- [x] #1127
- [x] #1135
- [x] #1134
- [x] #1137

#1137 removes the first-call compile time that #1128 added, which the
TTFX check flagged on this PR.

#1132 merged into the branch of #1131 and is part of its commit.

Not bug fixes: #1011 adds a deprecation, #1109 changes the `sprand`
value stream for a value function, #1113 changes the result shape of
`SparseMatrixCSC` of a vector view, and #1119, #1133, #1134 and #1135
add methods for views. They are included because they are labelled and
1.14 is not released yet.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Viral B. Shah <ViralBShah@users.noreply.github.com>
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