Skip to content

[repo-assist] perf: use HashSet for culture-code lookup in processFolder - #1241

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/perf-hashset-cultures-18de1e970b2e2265
Draft

[repo-assist] perf: use HashSet for culture-code lookup in processFolder#1241
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/perf-hashset-cultures-18de1e970b2e2265

Conversation

@github-actions

@github-actions github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Summary

Replace Array.distinct + Array.contains (O(n)) with HashSet<string> (O(1)) for the per-directory language-code check in processFolder.

Details

In DocContent.processFolder, every directory traversed checks whether its two-letter name is a known culture code to decide if it is an "other language" subdirectory:

// Before
let allCultures =
    CultureInfo.GetCultures(CultureTypes.AllCultures)
    |> Array.choose (...)
    |> Array.distinct          // O(n2) dedup

let isOtherLang = ... && allCultures |> Array.contains indirName  // O(n) per call

With ~800 culture codes in CultureTypes.AllCultures, each Array.contains call scans up to 800 strings. On a large docs site with many nested directories this adds up.

// After
let allCultures =
    CultureInfo.GetCultures(CultureTypes.AllCultures)
    |> Array.choose (...)
    |> HashSet<string>          // O(1) construction, O(1) lookup

let isOtherLang = ... && allCultures.Contains indirName  // O(1) per call

The Array.distinct step is also removed because HashSet deduplicates automatically.

Test Status

  • dotnet build src/fsdocs-tool/fsdocs-tool.fsproj --configuration Release — passed
  • dotnet fantomas src/fsdocs-tool/BuildCommand.fs --check — no formatting changes required

Generated by 🌈 Repo Assist, see workflow run. Learn more.
Comment /repo-assist to run again

Add this agentic workflow to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@42c2ab5b4e4c9273534c39259b2e0df7f20f07e9

Replace Array.distinct + Array.contains (O(n)) with HashSet<string>
(O(1)) for the per-directory language-code check in processFolder.

On a site with many nested directories this check was called for every
directory traversed. With the previous Array.contains the cost grew
linearly with the number of supported culture codes (~800).
HashSet.Contains makes each check O(1).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants