From ed0d470113fdd75272dbffa7b7a2fb290839b1f9 Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Mon, 15 Feb 2021 13:36:36 +0100 Subject: [PATCH] (perf) simple performance tests --- .../typescript/testfiles/performance.svelte | 30 ++++++++++++ .../typescript/typescript-performance.test.ts | 46 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 packages/language-server/test/plugins/typescript/testfiles/performance.svelte create mode 100644 packages/language-server/test/plugins/typescript/typescript-performance.test.ts diff --git a/packages/language-server/test/plugins/typescript/testfiles/performance.svelte b/packages/language-server/test/plugins/typescript/testfiles/performance.svelte new file mode 100644 index 000000000..e840eac7c --- /dev/null +++ b/packages/language-server/test/plugins/typescript/testfiles/performance.svelte @@ -0,0 +1,30 @@ + + +
+

lorem ipsum

+ +
+ + { + const result = evt.detail ? aFunction(false) : aFunction('right'); + result; + }} +> +

Inner Content

+
diff --git a/packages/language-server/test/plugins/typescript/typescript-performance.test.ts b/packages/language-server/test/plugins/typescript/typescript-performance.test.ts new file mode 100644 index 000000000..ba98e5b53 --- /dev/null +++ b/packages/language-server/test/plugins/typescript/typescript-performance.test.ts @@ -0,0 +1,46 @@ +import * as path from 'path'; +import { performance } from 'perf_hooks'; +import ts from 'typescript'; +import { Position, Range } from 'vscode-languageserver'; +import { Document, DocumentManager } from '../../../src/lib/documents'; +import { LSConfigManager } from '../../../src/ls-config'; +import { TypeScriptPlugin } from '../../../src/plugins'; +import { pathToUrl } from '../../../src/utils'; + +describe('TypeScript Plugin Performance Tests', () => { + function setup(filename: string) { + const docManager = new DocumentManager(() => document); + const testDir = path.join(__dirname, 'testfiles'); + const filePath = path.join(testDir, filename); + const uri = pathToUrl(filePath); + const document = new Document(uri, ts.sys.readFile(filePath) || ''); + const pluginManager = new LSConfigManager(); + const plugin = new TypeScriptPlugin(docManager, pluginManager, [pathToUrl(testDir)]); + docManager.openDocument({ uri, text: document.getText() }); + const updateDocument = (newText: string) => + docManager.updateDocument({ uri, version: 1 }, [ + { range: Range.create(Position.create(9, 0), Position.create(9, 0)), text: newText } + ]); + return { plugin, document, updateDocument }; + } + + it('should be fast enough', async () => { + const { document, plugin, updateDocument } = setup('performance'); + + const start = performance.now(); + for (let i = 0; i < 1000; i++) { + await plugin.doHover(document, Position.create(1, 15)); + await plugin.getDiagnostics(document); + await plugin.findReferences(document, Position.create(1, 15), { + includeDeclaration: true + }); + await plugin.getDocumentSymbols(document); + await plugin.getSemanticTokens(document); + await plugin.prepareRename(document, Position.create(1, 15)); + updateDocument('function asd() {}\n'); + } + const end = performance.now(); + + console.log(`Performance test took ${end - start}ms`); + }).timeout(10000); +});