mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-22 03:26:22 +00:00
profiling, better concurrency heuristics
This commit is contained in:
parent
68ccd1d79d
commit
cea6834fef
4 changed files with 9 additions and 6 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,6 +2,7 @@
|
||||||
.gitignore
|
.gitignore
|
||||||
node_modules
|
node_modules
|
||||||
public
|
public
|
||||||
|
prof
|
||||||
tsconfig.tsbuildinfo
|
tsconfig.tsbuildinfo
|
||||||
.obsidian
|
.obsidian
|
||||||
.quartz-cache
|
.quartz-cache
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
title: Making your own plugins
|
title: Making your own plugins
|
||||||
---
|
---
|
||||||
|
|
||||||
This part of the documentation will assume you have some basic coding knowledge and will include code snippets that describe the interface of what Quartz plugins should look like.
|
This part of the documentation will assume you have some basic coding knowledge in TypeScript and will include code snippets that describe the interface of what Quartz plugins should look like.
|
||||||
|
|
||||||
![[quartz-transform-pipeline.png]]
|
![[quartz-transform-pipeline.png]]
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,8 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"check": "tsc --noEmit && npx prettier . --check",
|
"check": "tsc --noEmit && npx prettier . --check",
|
||||||
"format": "npx prettier . --write",
|
"format": "npx prettier . --write",
|
||||||
"test": "tsx ./quartz/path.test.ts"
|
"test": "tsx ./quartz/path.test.ts",
|
||||||
|
"profile": "0x -D prof ./quartz/bootstrap-cli.mjs build --concurrency=1"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"site generator",
|
"site generator",
|
||||||
|
|
|
@ -9,7 +9,6 @@ import { PerfTimer } from "../perf"
|
||||||
import { read } from "to-vfile"
|
import { read } from "to-vfile"
|
||||||
import { FilePath, QUARTZ, slugifyFilePath } from "../path"
|
import { FilePath, QUARTZ, slugifyFilePath } from "../path"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import os from "os"
|
|
||||||
import workerpool, { Promise as WorkerPromise } from "workerpool"
|
import workerpool, { Promise as WorkerPromise } from "workerpool"
|
||||||
import { QuartzLogger } from "../log"
|
import { QuartzLogger } from "../log"
|
||||||
import { trace } from "../trace"
|
import { trace } from "../trace"
|
||||||
|
@ -82,6 +81,7 @@ export function createFileParser(ctx: BuildCtx, fps: FilePath[]) {
|
||||||
const res: ProcessedContent[] = []
|
const res: ProcessedContent[] = []
|
||||||
for (const fp of fps) {
|
for (const fp of fps) {
|
||||||
try {
|
try {
|
||||||
|
const perf = new PerfTimer()
|
||||||
const file = await read(fp)
|
const file = await read(fp)
|
||||||
|
|
||||||
// strip leading and trailing whitespace
|
// strip leading and trailing whitespace
|
||||||
|
@ -101,7 +101,7 @@ export function createFileParser(ctx: BuildCtx, fps: FilePath[]) {
|
||||||
res.push([newAst, file])
|
res.push([newAst, file])
|
||||||
|
|
||||||
if (argv.verbose) {
|
if (argv.verbose) {
|
||||||
console.log(`[process] ${fp} -> ${file.data.slug}`)
|
console.log(`[process] ${fp} -> ${file.data.slug} (${perf.timeSince()})`)
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
trace(`\nFailed to process \`${fp}\``, err as Error)
|
trace(`\nFailed to process \`${fp}\``, err as Error)
|
||||||
|
@ -112,14 +112,15 @@ export function createFileParser(ctx: BuildCtx, fps: FilePath[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const clamp = (num: number, min: number, max: number) => Math.min(Math.max(Math.round(num), min), max);
|
||||||
export async function parseMarkdown(ctx: BuildCtx, fps: FilePath[]): Promise<ProcessedContent[]> {
|
export async function parseMarkdown(ctx: BuildCtx, fps: FilePath[]): Promise<ProcessedContent[]> {
|
||||||
const { argv } = ctx
|
const { argv } = ctx
|
||||||
const perf = new PerfTimer()
|
const perf = new PerfTimer()
|
||||||
const log = new QuartzLogger(argv.verbose)
|
const log = new QuartzLogger(argv.verbose)
|
||||||
|
|
||||||
|
// rough heuristics: 128 gives enough time for v8 to JIT and optimize parsing code paths
|
||||||
const CHUNK_SIZE = 128
|
const CHUNK_SIZE = 128
|
||||||
let concurrency =
|
const concurrency = ctx.argv.concurrency ?? clamp(fps.length / CHUNK_SIZE, 1, 4)
|
||||||
ctx.argv.concurrency ?? (fps.length < CHUNK_SIZE ? 1 : os.availableParallelism())
|
|
||||||
|
|
||||||
let res: ProcessedContent[] = []
|
let res: ProcessedContent[] = []
|
||||||
log.start(`Parsing input files using ${concurrency} threads`)
|
log.start(`Parsing input files using ${concurrency} threads`)
|
||||||
|
|
Loading…
Reference in a new issue