← Back to Pull requests

Revert "strings: fast path for `String` conversion of dense StringVie… #63740

Open
nhz2 opened this pull request with 35 lines diff across 2 files
View on GitHub
nhz2 nhz2 commented on Oct 11, 2026 18:48 UTC
Author

…ws (#62483)"

This reverts commit 8ffa5f0ef717148bf25c0a79ffaf202484784d13.

#62483 made assumptions about DenseArray that are not always true. These kinds of generic functions that use pointer are almost always going to be incorrect given the current state of DenseArray and pointer.

Fixes #63361

CC: @jakobnissen @KristofferC

Diff: 35 lines (+33 / -2) across 2 files Reviewer: stevengj Review duration: 27617m
All Vouch review confidence checks passed
Residual risk 0.02 = Change Risk (0.26) × (1 − Review Confidence (0.92)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.26 · 35 lines diff across 2 files
0.26
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.91 · 4 substantive comment(s)
0.91
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
91%
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
Diff Size diff_size
0.214
Real PR Conversation Timeline
5 items
stevengj stevengj commented on code on Oct 12, 2026 01:15 UTC
Code Review
base/strings/stringview.jl:1
@@ -23,8 +23,6 @@ pointer(x::SubString{<:DenseStringView}, i::Integer) = pointer(x.string) + x.off
 unsafe_convert(::Type{Ptr{UInt8}}, s::DenseStringViewAndSub) = pointer(s)
 unsafe_convert(::Type{Ptr{Int8}}, s::DenseStringViewAndSub) = convert(Ptr{Int8}, pointer(s))
 
-String(s::DenseStringViewAndSub) = GC.@preserve s unsafe_string(pointer(s), ncodeunits(s))

I would rather have something analogous to #63375 for the time being, which at least keeps the fast path for Union{Vector{UInt8}, Memory{UInt8}} and subarrays thereof (with a TODO comment to revise in the future if we get some kind of better trait or abstract type for this).

KristofferC KristofferC commented on code on Oct 12, 2026 10:14 UTC
Code Review
base/strings/stringview.jl:1
@@ -23,8 +23,6 @@ pointer(x::SubString{<:DenseStringView}, i::Integer) = pointer(x.string) + x.off
 unsafe_convert(::Type{Ptr{UInt8}}, s::DenseStringViewAndSub) = pointer(s)
 unsafe_convert(::Type{Ptr{Int8}}, s::DenseStringViewAndSub) = convert(Ptr{Int8}, pointer(s))
 
-String(s::DenseStringViewAndSub) = GC.@preserve s unsafe_string(pointer(s), ncodeunits(s))

I would also prefer to have the common case specialized so at least that gets to benefit from this.

KristofferC KristofferC commented on Oct 12, 2026 10:19 UTC
Contributor

I added a commit that only opted into this for "cpu strings". But note that this is really not the only place where this is done:

Symbol:
https://github.com/JuliaLang/julia/blob/5900a4cf53eff80401f7b7f075f8563868869e03/base/strings/stringview.jl#L15

hash:
https://github.com/JuliaLang/julia/blob/5900a4cf53eff80401f7b7f075f8563868869e03/base/strings/stringview.jl#L109

Regex (PCRE gets the pointer for any DenseUTF8String):
https://github.com/JuliaLang/julia/blob/5900a4cf53eff80401f7b7f075f8563868869e03/base/pcre.jl#L205-L213

Float parsing:
https://github.com/JuliaLang/julia/blob/5900a4cf53eff80401f7b7f075f8563868869e03/base/parse.jl#L264-L265

startswith / endswith (memcmp):
https://github.com/JuliaLang/julia/blob/5900a4cf53eff80401f7b7f075f8563868869e03/base/strings/util.jl#L73
https://github.com/JuliaLang/julia/blob/5900a4cf53eff80401f7b7f075f8563868869e03/base/strings/util.jl#L111

memchr / memrchr for any DenseArray{UInt8}:
https://github.com/JuliaLang/julia/blob/5900a4cf53eff80401f7b7f075f8563868869e03/base/strings/search.jl#L25-L27
https://github.com/JuliaLang/julia/blob/5900a4cf53eff80401f7b7f075f8563868869e03/base/strings/search.jl#L185-L186
https://github.com/JuliaLang/julia/blob/5900a4cf53eff80401f7b7f075f8563868869e03/base/strings/search.jl#L249-L250

IO: read! / write treat any DenseArray as contiguous and pass pointer(A) on:
https://github.com/JuliaLang/julia/blob/5900a4cf53eff80401f7b7f075f8563868869e03/base/reshapedarray.jl#L420
https://github.com/JuliaLang/julia/blob/5900a4cf53eff80401f7b7f075f8563868869e03/base/io.jl#L1020
https://github.com/JuliaLang/julia/blob/5900a4cf53eff80401f7b7f075f8563868869e03/base/io.jl#L943

stevengj stevengj commented on Oct 12, 2026 10:32 UTC
Contributor

As I wrote in https://github.com/JuliaLang/julia/pull/63375#issuecomment-5904051487

Alternatively, I wonder if the definition DenseArray should be updated to say that the contents are stored contiguously in CPU memory. What is gained by allowing something like a GPU array to be a DenseArray? When would it be useful to dispatch to a specialized DenseArray method for a GPU array?

Reviewers
Assignees
nhz2 nhz2
Labels
risk: low confidence: 91.5% 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: 25.9% (LOW) · Higher = larger blast radius
25.9%
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: 91.5% · Lower = rushed or shallow review
91.5%
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: 2.2% · Safe to merge
2.2%