Skip to content

docparse: speed up doc generation via parallel parsing and package preloading - #115

Merged
shane-tw merged 1 commit into
masterfrom
perf/parallel-file-parsing
Jul 1, 2026
Merged

docparse: speed up doc generation via parallel parsing and package preloading#115
shane-tw merged 1 commit into
masterfrom
perf/parallel-file-parsing

Conversation

@shane-tw

@shane-tw shane-tw commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

What changed

Parallel file parsing in FindComments

Previously FindComments parsed source files serially (one at a time in a loop). Now all files are parsed concurrently using a WaitGroup, with each goroutine owning its own token.FileSet. The parsed results are collected into a []parsedFile slice before any serial processing begins.

Cross-phase AST reuse (astFileCache)

FindComments and getDecls both call parser.ParseFile on the same set of source files. The parsed *ast.File values are now cached in a sync.Map (astFileCache) keyed by absolute path. getDecls checks this cache first; files already parsed during comment extraction are reused at zero I/O cost. Files not in the cache are parsed concurrently inside getDecls as well.

Batch package preloading (preloadPackages)

Before the serial endpoint-processing loop, all packages imported by the scanned files are resolved in a single packages.Load call (one go list invocation). The results are used to pre-populate resolvedPkgCache and declsCache, so the serial loop hits no cold build.Import calls.

Failure caching in resolvedPkgCache

Package lookups are cached as a pkgResult{pkg, err} struct — both successes and failures. Short local names (e.g. "payload") that cannot be resolved directly always failed build.Import, but without caching those failures the same failed call repeated for every unique type reference. Now each import path is tried at most twice per run.

Test plan

  • go test ./... passes
  • All existing snapshot tests pass unchanged
  • Linter passes

@coveralls

coveralls commented Jul 1, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 28533681959

Coverage increased (+1.8%) to 55.423%

Details

  • Coverage increased (+1.8%) from the base build.
  • Patch coverage: 22 uncovered changes across 1 file (143 of 165 lines covered, 86.67%).
  • 2 coverage regressions across 1 file.

Uncovered Changes

File Changed Covered %
docparse/find.go 165 143 86.67%

Coverage Regressions

2 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
docparse/find.go 2 58.8%

Coverage Stats

Coverage Status
Relevant Lines: 2351
Covered Lines: 1303
Line Coverage: 55.42%
Coverage Strength: 40.51 hits per line

💛 - Coveralls

@shane-tw shane-tw changed the title docparse: parse source files in parallel docparse: speed up doc generation via parallel parsing and package preloading Jul 1, 2026
@shane-tw
shane-tw force-pushed the perf/parallel-file-parsing branch from 9913d8d to 2debc05 Compare July 1, 2026 16:51
…eloading

- Parse all source files concurrently in FindComments using a WaitGroup;
  each goroutine owns its own token.FileSet.
- Cache parsed *ast.File values by absolute path (astFileCache sync.Map)
  so getDecls reuses already-parsed ASTs instead of re-reading files.
- Parallel-parse any uncached files inside getDecls as well.
- Batch-resolve all imported packages with a single packages.Load call
  (preloadPackages) before the serial endpoint-processing loop, pre-populating
  resolvedPkgCache and declsCache to eliminate cold build.Import calls.
- Cache both successes and failures in resolvedPkgCache (pkgResult) so
  short package names that fail the first lookup are not retried repeatedly.
- Emit progress lines to stderr so users can see what is happening.
@shane-tw
shane-tw force-pushed the perf/parallel-file-parsing branch from 2debc05 to e03ce62 Compare July 1, 2026 16:57
@shane-tw
shane-tw merged commit 84b3c21 into master Jul 1, 2026
2 checks passed
@shane-tw
shane-tw deleted the perf/parallel-file-parsing branch July 7, 2026 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants