Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions src/ProvidedTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4586,29 +4586,25 @@ module internal AssemblyReader =

let mkCacheInt32 lowMem _infile _nm _sz =
if lowMem then (fun f x -> f x) else
let cache = Dictionary<int32, _>()
let syncObj = obj()
let cache = ConcurrentDictionary<int32, _>()
fun f (idx:int32) ->
lock syncObj (fun () ->
let mutable res = Unchecked.defaultof<_>
if cache.TryGetValue(idx, &res) then res
else
let v = f idx
cache.[idx] <- v
v)
match cache.TryGetValue idx with
| true, v -> v
| false, _ ->
let v = f idx
cache.TryAdd(idx, v) |> ignore
cache.[idx]
Comment on lines +4589 to +4596
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cache.TryGetValue idx uses the F# out-arg-to-tuple translation, which allocates a tuple on every cache access (including hits). Since this cache is likely hot, consider using the byref overload (let mutable res = Unchecked.defaultof<_>; if cache.TryGetValue(idx, &res) then res else ...) to avoid per-call allocations. Also, after TryAdd you can return v directly when the add succeeds to avoid a second dictionary lookup.

Copilot uses AI. Check for mistakes.

let mkCacheGeneric lowMem _inbase _nm _sz =
if lowMem then (fun f x -> f x) else
let cache = Dictionary<'T, _>()
let syncObj = obj()
let cache = ConcurrentDictionary<'T, _>()
fun f (idx :'T) ->
lock syncObj (fun () ->
match cache.TryGetValue idx with
| true, cached -> cached
| false, _ ->
let v = f idx
cache.[idx] <- v
v)
match cache.TryGetValue idx with
| true, v -> v
| false, _ ->
let v = f idx
cache.TryAdd(idx, v) |> ignore
cache.[idx]
Comment on lines +4602 to +4607
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After computing v on a miss, the code does TryAdd and then unconditionally reads cache.[idx], which forces another lookup. Consider returning v when TryAdd succeeds (and only falling back to reading from the dictionary when it fails due to a concurrent add). This keeps the concurrent behavior but avoids extra work on every miss.

Copilot uses AI. Check for mistakes.

let seekFindRow numRows rowChooser =
let mutable i = 1
Expand Down
Loading