@@ -32,9 +32,11 @@ type PositionedToken = ThemedToken & { start: number; end: number };
32
32
/**
33
33
* Due to a combination of memory limitations of Cloudflare workers and the memory
34
34
* cost of shiki, we need to set a limit on the number of lines we can highlight.
35
+ *
36
+ * This is done per invocation of the Cloudflare worker, so we can store it in-memory.
35
37
*/
36
38
let lineCount = 0 ;
37
- const LINE_LIMIT = 2000 ;
39
+ const LINE_LIMIT = 750 ;
38
40
39
41
/**
40
42
* Highlight a code block while preserving inline elements.
@@ -312,9 +314,11 @@ function cleanupLine(line: string): string {
312
314
return line . replace ( / \r / g, '' ) ;
313
315
}
314
316
315
- let memoryHighlighter : HighlighterGeneric < any , any > | undefined = undefined ;
316
-
317
- const loadHighlighterSingleton = singleton ( async ( ) => {
317
+ /**
318
+ * Load the highlighter, only once, and reuse it.
319
+ * It makes sure to handle concurrent calls.
320
+ */
321
+ const loadHighlighter = singleton ( async ( ) => {
318
322
return await trace ( 'highlighting.loadHighlighter' , async ( ) => {
319
323
if ( typeof onigWasm !== 'string' ) {
320
324
// When running bun test, the import is a string, we ignore it and let the module
@@ -323,27 +327,14 @@ const loadHighlighterSingleton = singleton(async () => {
323
327
// Otherwise for Vercel/Cloudflare, we need to load it ourselves.
324
328
await loadWasm ( ( obj ) => WebAssembly . instantiate ( onigWasm , obj ) ) ;
325
329
}
326
- console . log ( 'getHighlighter' ) ;
327
330
const highlighter = await getHighlighter ( {
328
331
themes : [ createCssVariablesTheme ( ) ] ,
329
332
langs : [ ] ,
330
333
} ) ;
331
- memoryHighlighter = highlighter ;
332
334
return highlighter ;
333
335
} ) ;
334
336
} ) ;
335
337
336
- /**
337
- * Load the highlighter, only once, and reuse it.
338
- * It makes sure to handle concurrent calls.
339
- */
340
- const loadHighlighter = ( ) => {
341
- if ( memoryHighlighter ) {
342
- return Promise . resolve ( memoryHighlighter ) ;
343
- }
344
- return loadHighlighterSingleton ( ) ;
345
- } ;
346
-
347
338
const loadLanguagesMutex = asyncMutexFunction ( ) ;
348
339
async function loadHighlighterLanguage (
349
340
highlighter : HighlighterGeneric < keyof typeof bundledLanguages , keyof typeof bundledThemes > ,
0 commit comments