Skip to content

perf(core): skip search index generation when search is disabled#3031

Merged
SoonIter merged 1 commit intomainfrom
syt-vibe-kanban/8c50-search-false-sea
Jan 20, 2026
Merged

perf(core): skip search index generation when search is disabled#3031
SoonIter merged 1 commit intomainfrom
syt-vibe-kanban/8c50-search-false-sea

Conversation

@SoonIter
Copy link
Copy Markdown
Member

@SoonIter SoonIter commented Jan 20, 2026

Summary

Optimize build performance by skipping search index content generation when search: false is configured.

Related Issue

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

AI Summary

What changes were made

  1. Added searchEnabled option to ExtractPageDataOptions in extractPageData.ts

    • New optional boolean parameter to control search index generation
  2. Modified getPageIndexInfoByRoute function in extractPageData.ts

    • When searchEnabled is false, the function now returns early with:
      • Empty content field (no search content generated)
      • TOC items with charIndex: -1 (skip character index calculation)
      • Essential metadata preserved (title, description, frontmatter)
    • Skips expensive operations: processor.run() and processor.stringify()
  3. Updated createPageData function in createPageData.ts

    • Determines searchEnabled based on whether search config is false
    • Fixed searchCodeBlocks logic to properly handle when searchConfig is false
    • Passes searchEnabled to extractPageData

Why these changes were made

When users configure search: false in their Rspress config (e.g., when using external search solutions like Algolia), the build process was still performing unnecessary work to generate search index content. This optimization:

  • Reduces build time by skipping markdown processing for search
  • Reduces memory usage by not storing search content
  • Maintains all other page metadata needed for rendering

Implementation details

  • The optimization is applied at the earliest possible point in extractPageData.ts
  • Basic page information (title, TOC structure, frontmatter, description) is still extracted for other features
  • Only search-specific processing is skipped (content stringification and charIndex calculation)
  • Default behavior (searchEnabled: true) is preserved for backward compatibility

This PR was written using Vibe Kanban


## 修改内容

### 1. `packages/core/src/node/route/extractPageData.ts`

- 在 `ExtractPageDataOptions` 接口中添加了 `searchEnabled?: boolean` 选项
- 在 `getPageIndexInfoByRoute` 函数中:
  - 解构获取 `searchEnabled`(默认为 `true`)
  - 当 `searchEnabled` 为 `false` 时,跳过以下搜索索引相关的处理:
    - 跳过运行 processor 插件生成搜索内容
    - 跳过计算 TOC 的 `charIndex`(设为 -1)
    - 返回空的 `content` 字段
  - 仍然保留必要的信息:title、toc(无 charIndex)、description、frontmatter 等

### 2. `packages/core/src/node/runtimeModule/pageData/createPageData.ts`

- 从 `userConfig?.search` 获取搜索配置
- 判断 `searchEnabled = searchConfig !== false`
- 修复了 `searchCodeBlocks` 的判断逻辑,确保在 `searchConfig` 为 `false` 时不会出错
- 将 `searchEnabled` 传递给 `extractPageData`

## 优化效果

当配置 `search: false` 时:
- 跳过 markdown 内容的处理和转换(`processor.run` 和 `processor.stringify`)
- 跳过 TOC charIndex 的计算逻辑
- 返回空的 `content`,减少内存占用
- 保留基本的页面元数据(title、toc、frontmatter 等)供其他功能使用
Copilot AI review requested due to automatic review settings January 20, 2026 09:15
@netlify
Copy link
Copy Markdown

netlify Bot commented Jan 20, 2026

Deploy Preview for rspress-v2 ready!

Name Link
🔨 Latest commit 7229297
🔍 Latest deploy log https://app.netlify.com/projects/rspress-v2/deploys/696f47b76db8020008235cc4
😎 Deploy Preview https://deploy-preview-3031--rspress-v2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@SoonIter SoonIter changed the title 优化 search: false 时跳过 searchIndex 生成, 在 extractPageData 中 (vibe-kanban) perf(core): skip search index generation when search is disabled Jan 20, 2026
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying rspress-main with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7229297
Status:🚫  Build failed.

View logs

@github-actions
Copy link
Copy Markdown
Contributor

Rsdoctor Bundle Diff Analysis

Found 3 projects in monorepo, 1 project with changes.

📊 Quick Summary
Project Total Size Change
node 10.5 MB 0
node_md 1.3 MB 0
web 15.4 MB 📉 -584.0 KB (-3.6%)
📋 Detailed Reports (Click to expand)

📁 web

Path: website/doc_build/diff-rsdoctor/web/rsdoctor-data.json

📌 Baseline Commit: 0fcf7af2f6 | PR: #3030

Metric Current Baseline Change
📊 Total Size 15.4 MB 16.0 MB -584.0 KB (-3.6%)
📄 JavaScript 15.2 MB 15.2 MB -1.6 KB (-0.0%)
🎨 CSS 126.6 KB 126.6 KB 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 148.7 KB 731.0 KB -582.3 KB (-79.7%)

📦 Download Diff Report: web Bundle Diff

Generated by Rsdoctor GitHub Action

@SoonIter SoonIter requested a review from Timeless0911 January 20, 2026 09:19
@SoonIter SoonIter enabled auto-merge (squash) January 20, 2026 09:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

该 PR 旨在在用户配置 search: false 时,减少/跳过搜索索引相关内容的生成开销(将跳过搜索内容的处理与 stringify)。

Changes:

  • createPageData 中识别 search: false 并透传 searchEnabledextractPageData
  • extractPageData/getPageIndexInfoByRoute 中新增 searchEnabled 选项,并在关闭时提前返回,避免生成搜索用的 content

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/core/src/node/runtimeModule/pageData/createPageData.ts 解析 search 配置并新增 searchEnabled,传入页面数据提取流程
packages/core/src/node/route/extractPageData.ts 新增 searchEnabled 参数;关闭搜索时跳过搜索索引内容生成(processor.run/stringify)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/core/src/node/runtimeModule/pageData/createPageData.ts
Comment thread packages/core/src/node/route/extractPageData.ts
@SoonIter SoonIter merged commit f49de1c into main Jan 20, 2026
16 of 17 checks passed
@SoonIter SoonIter deleted the syt-vibe-kanban/8c50-search-false-sea branch January 20, 2026 09:29
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.

3 participants