Skip to content

Commit fe74fc9

Browse files
authored
(perf) simple performance tests (#819)
part of #676
1 parent c3468e3 commit fe74fc9

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<script lang="ts">
2+
function aFunction(param: string) {
3+
param += 1; // should error
4+
const foo = subFunction();
5+
6+
function subFunction() {
7+
return param ? 1 : 2;
8+
}
9+
}
10+
11+
function action(node: HTMLElement) {
12+
aFunction(true); // should error
13+
const foo = 'bar';
14+
}
15+
</script>
16+
17+
<div use:action>
18+
<p>lorem ipsum</p>
19+
<slot />
20+
</div>
21+
22+
<NonExistentComponent
23+
propA={1}
24+
on:event={(evt) => {
25+
const result = evt.detail ? aFunction(false) : aFunction('right');
26+
result;
27+
}}
28+
>
29+
<p>Inner Content</p>
30+
</NonExistentComponent>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import * as path from 'path';
2+
import { performance } from 'perf_hooks';
3+
import ts from 'typescript';
4+
import { Position, Range } from 'vscode-languageserver';
5+
import { Document, DocumentManager } from '../../../src/lib/documents';
6+
import { LSConfigManager } from '../../../src/ls-config';
7+
import { TypeScriptPlugin } from '../../../src/plugins';
8+
import { pathToUrl } from '../../../src/utils';
9+
10+
describe('TypeScript Plugin Performance Tests', () => {
11+
function setup(filename: string) {
12+
const docManager = new DocumentManager(() => document);
13+
const testDir = path.join(__dirname, 'testfiles');
14+
const filePath = path.join(testDir, filename);
15+
const uri = pathToUrl(filePath);
16+
const document = new Document(uri, ts.sys.readFile(filePath) || '');
17+
const pluginManager = new LSConfigManager();
18+
const plugin = new TypeScriptPlugin(docManager, pluginManager, [pathToUrl(testDir)]);
19+
docManager.openDocument({ uri, text: document.getText() });
20+
const updateDocument = (newText: string) =>
21+
docManager.updateDocument({ uri, version: 1 }, [
22+
{ range: Range.create(Position.create(9, 0), Position.create(9, 0)), text: newText }
23+
]);
24+
return { plugin, document, updateDocument };
25+
}
26+
27+
it('should be fast enough', async () => {
28+
const { document, plugin, updateDocument } = setup('performance');
29+
30+
const start = performance.now();
31+
for (let i = 0; i < 1000; i++) {
32+
await plugin.doHover(document, Position.create(1, 15));
33+
await plugin.getDiagnostics(document);
34+
await plugin.findReferences(document, Position.create(1, 15), {
35+
includeDeclaration: true
36+
});
37+
await plugin.getDocumentSymbols(document);
38+
await plugin.getSemanticTokens(document);
39+
await plugin.prepareRename(document, Position.create(1, 15));
40+
updateDocument('function asd() {}\n');
41+
}
42+
const end = performance.now();
43+
44+
console.log(`Performance test took ${end - start}ms`);
45+
}).timeout(10000);
46+
});

0 commit comments

Comments
 (0)