⚡ perf(vscode): 代码阅读预览发给页面的块带内容指纹:扩展端按卡片内容、在源码里占的地方连同子块的指纹算摘要,页面按指纹认出没变的块沿用原来的对象,不再逐块深比内容,5126 行的文档到了比对 10.6ms → 0.4ms

This commit is contained in:
cruldra committed 2026-10-13 16:39:59 +11:00
1 parent ad5f559e92
commit 266dc42bc5
13 files changed
+194 -26

No files matched your search

@@ -1,13 +1,14 @@
// @vitest-environment happy-dom
import type { Root } from 'react-dom/client'
import type { BlockView, CallTree, DocumentMessage, ExtensionToWebview, WebviewToExtension } from './types'
import type { UnhashedBlock } from './testBlocks'
import type { CallTree, DocumentMessage, ExtensionToWebview, WebviewToExtension } from './types'
import type { ViewState, ViewStateStore } from './viewState'
import { act } from 'react'
import { createRoot } from 'react-dom/client'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { App } from './App'
import { NO_SPAN } from './testBlocks'
import { hashed, NO_SPAN } from './testBlocks'
import { createViewStateStore } from './viewState'
/**
@@ -113,7 +114,7 @@ async function deliver(msg: ExtensionToWebview): Promise<void> {
})
}
function block(id: string, anchor: string): BlockView {
function block(id: string, anchor: string): UnhashedBlock {
return {
id,
anchor,
@@ -127,8 +128,8 @@ function block(id: string, anchor: string): BlockView {
}
}
function documentOf(version: number, blocks: BlockView[]): DocumentMessage {
return { type: 'document', version, languageId: 'python', blocks, source: '', colors: { roles: [], runs: [] }, attributes: [], translators: [], translatorId: '', names: [] }
function documentOf(version: number, blocks: UnhashedBlock[]): DocumentMessage {
return { type: 'document', version, languageId: 'python', blocks: hashed(blocks), source: '', colors: { roles: [], runs: [] }, attributes: [], translators: [], translatorId: '', names: [] }
}
function tree(id: string, name: string): CallTree {
@@ -224,7 +225,7 @@ describe('代码配色跟着当前颜色主题', () => {
describe('一条消息只重画受影响的卡片', () => {
/** 三张卡片,译文里各有一个带下标的名字(下标 10、20、30) */
function named(id: string, name: string, offset: number, text = '调用'): BlockView {
function named(id: string, name: string, offset: number, text = '调用'): UnhashedBlock {
return { ...block(id, name), translation: [{ text, role: 'keyword' }, { text: name, role: 'function', offset }] }
}
const DOC = documentOf(3, [named('0', 'load', 10), named('1', 'save', 20), named('2', 'drop', 30)])