Skip to content

feat: ビルドパイプラインの最適化#120

Merged
coji merged 1 commit intomainfrom
feat/optimize-build-pipeline
Jan 11, 2026
Merged

feat: ビルドパイプラインの最適化#120
coji merged 1 commit intomainfrom
feat/optimize-build-pipeline

Conversation

@coji
Copy link
Owner

@coji coji commented Jan 11, 2026

概要

ドキュメントサイトのビルドパイプラインを最適化し、ビルド時間を約8%短縮しました。

変更内容

並列処理の導入

  • ドキュメントJSON生成とOGP画像生成を並列化(concurrency: 10)
  • unstable_concurrencyオプションでプリレンダリングを並列化

重複処理の削除

  • BM25インデックスは生成済みJSONから構築するように変更
  • MD→HTML変換の2重処理を解消

不要機能の削除

  • 未使用のPagefindインデックス生成を削除
  • build-index.tsを削除し、build-docs.tsに統合

ビルド時間

項目 以前 現在
合計 50秒 46秒
build:index 40秒 37秒
build:app 2.5秒 3秒

テスト

  • pnpm build 成功
  • pnpm typecheck 成功
  • 生成されたサイトの動作確認

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added concurrent prerendering capability for improved build performance.
  • Chores

    • Optimized build process with parallel documentation processing.
    • Streamlined search index generation from prebuilt documentation.

✏️ Tip: You can customize this high-level summary in your review settings.

- ドキュメントJSON生成とOGP画像生成を並列化 (concurrency: 10)
- BM25インデックスは生成済みJSONから構築(MD再処理を削除)
- 未使用のPagefind生成を削除
- unstable_concurrencyでプリレンダリングを並列化
- 不要なbuild-index.tsを削除し、build-docs.tsに統合

ビルド時間: 50秒 → 46秒 (約8%改善)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Jan 11, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

The build pipeline is restructured to separate documentation preprocessing from indexing. A new buildDocs function processes markdown files into JSON and OGP images. The BM25 index now builds from prebuilt JSON docs via buildBM25IndexFromDocs. Legacy build-index.ts is removed and build scripts refactored accordingly.

Changes

Cohort / File(s) Summary
Build Configuration
apps/react-router/package.json, apps/react-router/react-router.config.ts
Narrowed build script from wildcard to explicit task invocation. Extracted prerender logic into dedicated getPrerenderPaths helper and introduced concurrent prerendering with unstable_concurrency: 10 option.
Build Script Pipeline
apps/react-router/scripts/build-index.ts
Refactored build flow: replaced legacy sequential processing with new buildDocs() + buildBM25IndexFromDocs() pipeline, added output paths for JSON docs and OGP images, and appended final menu-building step.
Documentation Processing
packages/scripts/src/build-docs.ts
New file. Exports buildDocs() function that discovers markdown files, processes them in parallel batches, outputs structured JSON representations and OGP images, with per-document error handling and logging.
BM25 Index Generation
packages/scripts/src/build-bm25-index.ts
Major refactor: added new public function buildBM25IndexFromDocs() and BuildFromDocsOptions interface to build index from prebuilt JSON docs. Shifted from markdown file discovery to in-memory BuiltDoc array processing; updated generateDocumentSections() to accept explicit pathname, title, html parameters.
Legacy Index Builder Removal
packages/scripts/src/build-index.ts
File removed. Deleted entire legacy buildIndex() function that previously handled markdown discovery, doc fetching, asset generation, and PageFind indexing in a single pass.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • feat: prebuild menu #57: Modifies the index/build pipeline to add a prebuilt menu step (buildMenus) that is now invoked from the refactored build flow in this PR.
  • refactor: split out prebuild codes #59: Refactors the same build/prebuild pipeline; both PRs restructure how docs and menus are prebuilt and how build scripts consume those artifacts.

Poem

🐰 The build pipeline hops in parallel stride,
Docs prebuilt in JSON, assets as guide,
BM25 indexes bloom from prepped ground,
Menus assembled—a faster turnaround! ✨

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 723a436 and 6d15090.

📒 Files selected for processing (6)
  • apps/react-router/package.json
  • apps/react-router/react-router.config.ts
  • apps/react-router/scripts/build-index.ts
  • packages/scripts/src/build-bm25-index.ts
  • packages/scripts/src/build-docs.ts
  • packages/scripts/src/build-index.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@claude
Copy link

claude bot commented Jan 11, 2026

Claude finished @coji's task —— View job


Code Review: Build Pipeline Optimization

I've completed a comprehensive review of the build pipeline optimization PR. Here's my detailed analysis:

Tasks:

  • Read and analyze all changed files
  • Review parallelization implementation
  • Check for potential bugs and security issues
  • Evaluate performance optimizations
  • Assess code quality and best practices
  • Provide final review feedback

Overall Assessment: Excellent Optimization

This is a well-executed build pipeline optimization that delivers tangible performance improvements (50s → 46s, ~8% reduction) through smart architectural changes.

🎯 Strengths

1. Smart Parallelization Strategy

  • Document Processing: Implements proper batch processing with configurable concurrency (default: 10) in packages/scripts/src/build-docs.ts:49-93
  • Prerendering: Adds unstable_concurrency: 10 to React Router config for parallel page generation
  • Well-designed batching: Uses Promise.all() correctly within batches to avoid overwhelming the system

2. Eliminates Duplicate Processing

  • Before: MD files were processed twice (once for JSON, once for BM25 index)
  • After: BM25 index built directly from already-processed docs via buildBM25IndexFromDocs()
  • Smart data flow: build-index.ts now returns processed docs for reuse by search indexing

3. Clean Architecture Improvements

  • File consolidation: Removes old packages/scripts/src/build-index.ts and integrates functionality into build-docs.ts
  • Separation of concerns: Clear distinction between doc processing and index building
  • Maintainable code: Well-structured with proper error handling and logging

🔒 Security & Safety

  • No security risks - all changes are build-time optimizations
  • Proper error handling with try/catch blocks and null filtering
  • Input validation via regex patterns and file existence checks
  • No credentials or secrets exposed in any changes

🐛 Potential Issues & Suggestions

Minor Concerns:

  1. Memory Usage (packages/scripts/src/build-docs.ts:43):

    • Storing all results in memory before returning could be problematic for very large doc sets
    • Suggestion: Consider streaming results if document count grows significantly
  2. Error Resilience (packages/scripts/src/build-docs.ts:86-87):

    • Failed documents are logged but build continues
    • Suggestion: Consider adding failure threshold or retry logic for transient errors
  3. Concurrency Configuration:

    • Hardcoded concurrency values (10) in multiple places
    • Suggestion: Consider making this configurable via environment variable

Code Quality Observations:

  • TypeScript: Excellent type safety throughout
  • Error Handling: Comprehensive error logging and graceful failures
  • Performance: Smart use of batching and parallel processing
  • Readability: Clear variable names and logical structure

🚀 Performance Analysis

The 8% build time improvement comes from:

  1. Parallel document generation (biggest impact)
  2. Eliminating MD re-processing for search index
  3. Parallel prerendering during app build
  4. Removing unused Pagefind generation overhead

Expected scaling: Performance gains should increase with larger document sets.

📋 Test Coverage

  • ✅ Author confirmed pnpm build and pnpm typecheck pass
  • ✅ Generated site functionality verified
  • Recommendation: Consider adding integration tests for the build pipeline to catch regressions

🎉 Conclusion

This is a high-quality optimization that:

  • Delivers measurable performance improvements
  • Maintains code quality and safety standards
  • Uses modern async/await patterns correctly
  • Has minimal risk of introducing bugs

Recommendation: ✅ APPROVE - This PR is ready to merge.

The optimization strategy is sound, implementation is clean, and the performance gains are valuable for development velocity.


@coji coji merged commit e2726f4 into main Jan 11, 2026
1 check passed
@coji coji deleted the feat/optimize-build-pipeline branch January 11, 2026 11:31
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.

1 participant