← Back to Pull requests

Random: fast rand! for contiguous views of BitArray #65009

Open
unknown opened this pull request with 183 lines diff across 2 files
View on GitHub
unknown unknown commented on Nov 16, 2026 11:23 UTC
Author

Fixes #41862.

rand!(::BitArray) fills whole 64-bit chunks at once, but a view such as view(B, :) or
view(B, 3:70) fell back to the generic loop, one Bool at a time.

This adds a method for Base.FastContiguousSubArray{Bool,<:Any,<:BitArray}. Such a view covers
one contiguous run of bits in the parent, so the method fills the chunks spanning that run
with rand!(rng, view(chunks, ka:kb)) and then restores the parent's bits outside the view
in the first and last chunk. Non-contiguous views still use the generic path.

Timing from the issue (Julia 1.13.4 with this method loaded, Windows x86_64):

julia> x = falses(10^8); y = @view x[:];

julia> @elapsed rand!(y)   # before
0.374

julia> @elapsed rand!(y)   # after
0.00123                    # rand!(x) on the same machine: 0.00108

Tests added in stdlib/Random/test/runtests.jl cover view bounds at and around chunk
boundaries (including a view inside a single chunk), parent bits outside the view staying
untouched, a contiguous view of a BitMatrix, empty views, seeding reproducibility, and
MersenneTwister / RandomDevice.

Testing note: I don't have a source build of master. I loaded the new method into Julia
1.13.4's Random and ran 1.13.4's full Random test suite plus the new testset; all pass.

AI disclosure: I wrote this change with help from Claude (Anthropic): it drafted the method,
the tests and this description. I reviewed every line and ran the tests above.

Diff: 183 lines (+137 / -46) across 2 files Reviewer: oscardssmith Review duration: 20960m
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.36) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.36 · 183 lines diff across 2 files
0.36
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
46%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth shallow_review_depth
0.344
Diff Size diff_size
0.312
Real PR Conversation Timeline
1 comments
"Review active on #65009"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 46.7% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 35.6% (MEDIUM) · Higher = larger blast radius
35.6%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 46.7% · Lower = rushed or shallow review
46.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 19% · Safe to merge
19%