perf(editor): skip Markdown classification beyond the hard render cap (#34798)

Above the 1 MiB override cap a Markdown file can never render rich, so
skip the unsupported-syntax scan and keep those documents out of the
eligibility cache.

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
OrcaWin
2026-10-28 17:41:37 -07:00
committed by GitHub
co-authored by OrcaWin
parent 53cbc49e76
commit c8fe5d4b96
3 changed files with 32 additions and 1 deletions
@@ -4,6 +4,7 @@ import {
type MarkdownRichModeEligibility,
type MarkdownRichModeEligibilityDecision
} from './markdown-rich-mode'
import { exceedsMarkdownRenderOverrideSizeLimit } from './markdown-rich-size-limit'
type EligibilityCacheEntry = {
content: string
@@ -46,6 +47,10 @@ function getCachedMarkdownRichModeEligibilityDecision(params: {
}
const decision = getMarkdownRichModeEligibilityDecision({ content, sizeOverridden })
// Don't retain hard-cap documents; checked after lookup so cache hits skip the UTF-8 probe.
if (decision.exceedsSizeLimit && exceedsMarkdownRenderOverrideSizeLimit(content)) {
return decision
}
entries.unshift({ content, sizeOverridden, decision })
if (entries.length > MAX_ENTRIES) {
entries.length = MAX_ENTRIES
@@ -1,5 +1,6 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import * as roundTrip from './markdown-round-trip'
import { MARKDOWN_RENDER_OVERRIDE_MAX_SIZE_BYTES } from './markdown-rich-size-limit'
import { RICH_MARKDOWN_MAX_SIZE_BYTES } from '../../../../shared/constants'
import {
getMarkdownRichModeEligibility,
@@ -207,6 +208,24 @@ describe('getMarkdownRichModeUnsupportedMessage', () => {
unsupportedMessage: expect.any(String)
})
})
it.each([false, true])(
'reports only the size limit beyond the hard render cap, override=%s',
(sizeOverridden) => {
const content = `${'a'.repeat(MARKDOWN_RENDER_OVERRIDE_MAX_SIZE_BYTES)}\n[ref]: /docs\n`
const result = getMarkdownRichModeEligibility({ content, sizeOverridden })
expect(result).toEqual({
exceedsSizeLimit: true,
unsupportedMessage: null
})
expect(
getMarkdownRichModeEligibility({ content: '[ref]: /docs', sizeOverridden })
.unsupportedMessage
).not.toBeNull()
}
)
})
const decide = (content: string) =>
@@ -5,7 +5,10 @@ import {
getRichMarkdownRoundTripOutput
} from './markdown-round-trip'
import { extractFrontMatter } from './markdown-frontmatter'
import { canRenderMarkdownAtSize } from './markdown-rich-size-limit'
import {
canRenderMarkdownAtSize,
exceedsMarkdownRenderOverrideSizeLimit
} from './markdown-rich-size-limit'
import { translate } from '@/i18n/i18n'
import { encodeRawMarkdownHtmlForRichEditor } from './raw-markdown-html'
import { createRichMarkdownEditorCodec } from './rich-markdown-source-transport'
@@ -142,6 +145,10 @@ export function getMarkdownRichModeEligibilityDecision({
content: string
sizeOverridden: boolean
}): MarkdownRichModeEligibilityDecision {
// Past the hard cap neither mode renders rich, so the unsupported-syntax scan is moot.
if (exceedsMarkdownRenderOverrideSizeLimit(content)) {
return { exceedsSizeLimit: true, unsupportedReason: null }
}
return {
exceedsSizeLimit: !canRenderMarkdownAtSize(content, sizeOverridden),
unsupportedReason: getMarkdownRichModeUnsupportedReason(content)