perf: incremental rebuild (--fastRebuild v2 but default) (#1841)
* checkpoint * incremental all the things * properly splice changes array * smol doc update * update docs * make fancy logger dumb in ci
This commit is contained in:
		@@ -11,7 +11,7 @@ export async function emitContent(ctx: BuildCtx, content: ProcessedContent[]) {
 | 
			
		||||
  const perf = new PerfTimer()
 | 
			
		||||
  const log = new QuartzLogger(ctx.argv.verbose)
 | 
			
		||||
 | 
			
		||||
  log.start(`Emitting output files`)
 | 
			
		||||
  log.start(`Emitting files`)
 | 
			
		||||
 | 
			
		||||
  let emittedFiles = 0
 | 
			
		||||
  const staticResources = getStaticResourcesFromPlugins(ctx)
 | 
			
		||||
@@ -26,7 +26,7 @@ export async function emitContent(ctx: BuildCtx, content: ProcessedContent[]) {
 | 
			
		||||
            if (ctx.argv.verbose) {
 | 
			
		||||
              console.log(`[emit:${emitter.name}] ${file}`)
 | 
			
		||||
            } else {
 | 
			
		||||
              log.updateText(`Emitting output files: ${emitter.name} -> ${chalk.gray(file)}`)
 | 
			
		||||
              log.updateText(`${emitter.name} -> ${chalk.gray(file)}`)
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
        } else {
 | 
			
		||||
@@ -36,7 +36,7 @@ export async function emitContent(ctx: BuildCtx, content: ProcessedContent[]) {
 | 
			
		||||
            if (ctx.argv.verbose) {
 | 
			
		||||
              console.log(`[emit:${emitter.name}] ${file}`)
 | 
			
		||||
            } else {
 | 
			
		||||
              log.updateText(`Emitting output files: ${emitter.name} -> ${chalk.gray(file)}`)
 | 
			
		||||
              log.updateText(`${emitter.name} -> ${chalk.gray(file)}`)
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -7,12 +7,13 @@ import { Root as HTMLRoot } from "hast"
 | 
			
		||||
import { MarkdownContent, ProcessedContent } from "../plugins/vfile"
 | 
			
		||||
import { PerfTimer } from "../util/perf"
 | 
			
		||||
import { read } from "to-vfile"
 | 
			
		||||
import { FilePath, FullSlug, QUARTZ, slugifyFilePath } from "../util/path"
 | 
			
		||||
import { FilePath, QUARTZ, slugifyFilePath } from "../util/path"
 | 
			
		||||
import path from "path"
 | 
			
		||||
import workerpool, { Promise as WorkerPromise } from "workerpool"
 | 
			
		||||
import { QuartzLogger } from "../util/log"
 | 
			
		||||
import { trace } from "../util/trace"
 | 
			
		||||
import { BuildCtx } from "../util/ctx"
 | 
			
		||||
import { BuildCtx, WorkerSerializableBuildCtx } from "../util/ctx"
 | 
			
		||||
import chalk from "chalk"
 | 
			
		||||
 | 
			
		||||
export type QuartzMdProcessor = Processor<MDRoot, MDRoot, MDRoot>
 | 
			
		||||
export type QuartzHtmlProcessor = Processor<undefined, MDRoot, HTMLRoot>
 | 
			
		||||
@@ -175,21 +176,42 @@ export async function parseMarkdown(ctx: BuildCtx, fps: FilePath[]): Promise<Pro
 | 
			
		||||
      process.exit(1)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const mdPromises: WorkerPromise<[MarkdownContent[], FullSlug[]]>[] = []
 | 
			
		||||
    for (const chunk of chunks(fps, CHUNK_SIZE)) {
 | 
			
		||||
      mdPromises.push(pool.exec("parseMarkdown", [ctx.buildId, argv, chunk]))
 | 
			
		||||
    const serializableCtx: WorkerSerializableBuildCtx = {
 | 
			
		||||
      buildId: ctx.buildId,
 | 
			
		||||
      argv: ctx.argv,
 | 
			
		||||
      allSlugs: ctx.allSlugs,
 | 
			
		||||
      allFiles: ctx.allFiles,
 | 
			
		||||
      incremental: ctx.incremental,
 | 
			
		||||
    }
 | 
			
		||||
    const mdResults: [MarkdownContent[], FullSlug[]][] =
 | 
			
		||||
      await WorkerPromise.all(mdPromises).catch(errorHandler)
 | 
			
		||||
 | 
			
		||||
    const childPromises: WorkerPromise<ProcessedContent[]>[] = []
 | 
			
		||||
    for (const [_, extraSlugs] of mdResults) {
 | 
			
		||||
      ctx.allSlugs.push(...extraSlugs)
 | 
			
		||||
    const textToMarkdownPromises: WorkerPromise<MarkdownContent[]>[] = []
 | 
			
		||||
    let processedFiles = 0
 | 
			
		||||
    for (const chunk of chunks(fps, CHUNK_SIZE)) {
 | 
			
		||||
      textToMarkdownPromises.push(pool.exec("parseMarkdown", [serializableCtx, chunk]))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const mdResults: Array<MarkdownContent[]> = await Promise.all(
 | 
			
		||||
      textToMarkdownPromises.map(async (promise) => {
 | 
			
		||||
        const result = await promise
 | 
			
		||||
        processedFiles += result.length
 | 
			
		||||
        log.updateText(`text->markdown ${chalk.gray(`${processedFiles}/${fps.length}`)}`)
 | 
			
		||||
        return result
 | 
			
		||||
      }),
 | 
			
		||||
    ).catch(errorHandler)
 | 
			
		||||
 | 
			
		||||
    const markdownToHtmlPromises: WorkerPromise<ProcessedContent[]>[] = []
 | 
			
		||||
    processedFiles = 0
 | 
			
		||||
    for (const [mdChunk, _] of mdResults) {
 | 
			
		||||
      childPromises.push(pool.exec("processHtml", [ctx.buildId, argv, mdChunk, ctx.allSlugs]))
 | 
			
		||||
      markdownToHtmlPromises.push(pool.exec("processHtml", [serializableCtx, mdChunk]))
 | 
			
		||||
    }
 | 
			
		||||
    const results: ProcessedContent[][] = await WorkerPromise.all(childPromises).catch(errorHandler)
 | 
			
		||||
    const results: ProcessedContent[][] = await Promise.all(
 | 
			
		||||
      markdownToHtmlPromises.map(async (promise) => {
 | 
			
		||||
        const result = await promise
 | 
			
		||||
        processedFiles += result.length
 | 
			
		||||
        log.updateText(`markdown->html ${chalk.gray(`${processedFiles}/${fps.length}`)}`)
 | 
			
		||||
        return result
 | 
			
		||||
      }),
 | 
			
		||||
    ).catch(errorHandler)
 | 
			
		||||
 | 
			
		||||
    res = results.flat()
 | 
			
		||||
    await pool.terminate()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user