Skip to content

Commit 4fa671e

Browse files
[Repo Assist] Perf: precompute entity name counts in renderEntities (O(N) vs O(N²)) (#1071)
* Perf: precompute entity name counts in renderEntities to avoid O(N²) list scanning Previously, for each entity in the rendered list, the code scanned the entire entities list to count duplicates (List.filter ... List.length). With N entities this is O(N²). Replace with a single-pass List.countBy precomputation outside the loop, reducing to O(N). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * ci: trigger checks --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 5e3d985 commit 4fa671e

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/FSharp.Formatting.ApiDocs/GenerateHtml.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,14 @@ type HtmlRender(model: ApiDocModel, ?menuTemplateFolder: string) =
340340
]
341341
]
342342
tbody [] [
343+
let nameCounts = entities |> List.countBy (fun e -> e.Name) |> dict
344+
343345
for e in entities do
344346
tr [] [
345347
td [ Class "fsdocs-entity-name" ] [
346348
let nm = e.Name
347349

348-
let multi = (entities |> List.filter (fun e -> e.Name = nm) |> List.length) > 1
350+
let multi = nameCounts.[nm] > 1
349351

350352
let nmWithSiffix =
351353
if multi then

src/FSharp.Formatting.ApiDocs/GenerateMarkdown.fs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,13 @@ type MarkdownRender(model: ApiDocModel, ?menuTemplateFolder: string) =
137137
p [ !!"Description" ]
138138
p [ !!"Source" ] ] ]
139139
[ AlignLeft; AlignLeft; AlignCenter ]
140-
[ for e in entities do
140+
[ let nameCounts = entities |> List.countBy (fun e -> e.Name) |> dict
141+
142+
for e in entities do
141143
[ [ p
142144
[ let nm = e.Name
143145

144-
let multi = (entities |> List.filter (fun e -> e.Name = nm) |> List.length) > 1
146+
let multi = nameCounts.[nm] > 1
145147

146148
let nmWithSiffix =
147149
if multi then

0 commit comments

Comments
 (0)