Commit c7c8212
Simplify mkCacheInt32/mkCacheGeneric to use ConcurrentDictionary (#486)
`mkCacheInt32` and `mkCacheGeneric` were using `Dictionary` + `lock
syncObj`, serializing all cache access including expensive metadata
decode work.
## Changes
- **`mkCacheInt32` / `mkCacheGeneric`**: replaced `Dictionary` + `lock`
with `ConcurrentDictionary` using `TryGetValue` / `TryAdd`. No locks, no
`syncObj`.
```fsharp
let mkCacheInt32 lowMem _infile _nm _sz =
if lowMem then (fun f x -> f x) else
let cache = ConcurrentDictionary<int32, _>()
fun f (idx:int32) ->
match cache.TryGetValue idx with
| true, v -> v
| false, _ ->
let v = f idx
cache.TryAdd(idx, v) |> ignore
cache.[idx]
```
`GetOrAdd(key, factory)` was not usable here — F# type inference cannot
disambiguate it from `GetOrAdd(key, value)` when the value type is an
unconstrained generic. `TryAdd` has no overloads and sidesteps the
issue. On a concurrent cache miss, `f idx` may be computed twice (both
`GetOrAdd` with factory and this pattern share that behaviour per the
.NET docs), which is acceptable since these factories are pure metadata
reads.
<!-- START COPILOT CODING AGENT TIPS -->
---
⌨️ Start Copilot coding agent tasks without leaving your editor —
available in [VS Code](https://gh.io/cca-vs-code-docs), [Visual
Studio](https://gh.io/cca-visual-studio-docs), [JetBrains
IDEs](https://gh.io/cca-jetbrains-docs) and
[Eclipse](https://gh.io/cca-eclipse-docs).
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com>1 parent c38ff71 commit c7c8212
1 file changed
Lines changed: 14 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4586 | 4586 | | |
4587 | 4587 | | |
4588 | 4588 | | |
4589 | | - | |
4590 | | - | |
| 4589 | + | |
4591 | 4590 | | |
4592 | | - | |
4593 | | - | |
4594 | | - | |
4595 | | - | |
4596 | | - | |
4597 | | - | |
4598 | | - | |
| 4591 | + | |
| 4592 | + | |
| 4593 | + | |
| 4594 | + | |
| 4595 | + | |
| 4596 | + | |
4599 | 4597 | | |
4600 | 4598 | | |
4601 | 4599 | | |
4602 | | - | |
4603 | | - | |
| 4600 | + | |
4604 | 4601 | | |
4605 | | - | |
4606 | | - | |
4607 | | - | |
4608 | | - | |
4609 | | - | |
4610 | | - | |
4611 | | - | |
| 4602 | + | |
| 4603 | + | |
| 4604 | + | |
| 4605 | + | |
| 4606 | + | |
| 4607 | + | |
4612 | 4608 | | |
4613 | 4609 | | |
4614 | 4610 | | |
| |||
0 commit comments