Skip to content

Commit 003d043

Browse files
fix: Move performance monitoring into its own package (#8431)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 4c370a3 commit 003d043

23 files changed

Lines changed: 349 additions & 93 deletions

File tree

cspell.code-workspace

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
{ "path": "packages/cspell-json-reporter" },
1717
{ "path": "packages/cspell-lib" },
1818
{ "path": "packages/cspell-normalize-json" },
19+
{ "path": "packages/cspell-performance-monitor" },
1920
{ "path": "packages/cspell-pipe" },
2021
{ "path": "packages/cspell-resolver" },
2122
{ "path": "packages/cspell-service-bus" },

packages/cspell-dictionary/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"node": ">=20"
5555
},
5656
"dependencies": {
57+
"@cspell/cspell-performance-monitor": "workspace:*",
5758
"@cspell/cspell-pipe": "workspace:*",
5859
"@cspell/cspell-types": "workspace:*",
5960
"cspell-trie-lib": "workspace:*",
Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1 @@
1-
export function measurePerfStart(name: string): void {
2-
performance.mark(name + '-start');
3-
}
4-
5-
export function measurePerfEnd(name: string): void {
6-
performance.mark(name + '-end');
7-
performance.measure(name, name + '-start', name + '-end');
8-
}
9-
10-
/**
11-
* Creates performance marks and measures the time taken between them.
12-
* @param name - name of the performance entry
13-
* @returns a function to stop the timer.
14-
*/
15-
export function measurePerf(name: string): () => void {
16-
measurePerfStart(name);
17-
return () => {
18-
measurePerfEnd(name);
19-
};
20-
}
1+
export { measurePerf } from '@cspell/cspell-performance-monitor';

packages/cspell-lib/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"homepage": "https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell-lib#readme",
7878
"dependencies": {
7979
"@cspell/cspell-bundled-dicts": "workspace:*",
80+
"@cspell/cspell-performance-monitor": "workspace:*",
8081
"@cspell/cspell-pipe": "workspace:*",
8182
"@cspell/cspell-resolver": "workspace:*",
8283
"@cspell/cspell-types": "workspace:*",

packages/cspell-lib/src/lib/SpellingDictionary/DictionaryController/DictionaryLoader.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import type { Stats, TextFileResource, VFileSystem } from 'cspell-io';
1212
import { compareStats, toFileURL, urlBasename } from 'cspell-io';
1313

14-
import { measurePerfFn } from '../../perf/index.js';
14+
import { measurePerf } from '../../perf/index.js';
1515
import type {
1616
DictionaryDefinitionInlineInternal,
1717
DictionaryDefinitionInternal,
@@ -273,10 +273,7 @@ async function load(reader: Reader, uri: URL, options: LoadOptions): Promise<Spe
273273

274274
async function legacyWordList(reader: Reader, filename: URL, options: LoadOptions) {
275275
const lines = await reader.readLines(filename);
276-
return measurePerfFn('legacyWords', () => _legacyWordListSync(lines, filename, options));
277-
}
278-
279-
function _legacyWordListSync(lines: Iterable<string>, filename: URL, options: LoadOptions) {
276+
using _ = measurePerf('legacyWords');
280277
const words = pipe(
281278
lines,
282279
// Remove comments
@@ -290,10 +287,7 @@ function _legacyWordListSync(lines: Iterable<string>, filename: URL, options: Lo
290287

291288
async function wordsPerLineWordList(reader: Reader, filename: URL, options: LoadOptions) {
292289
const lines = await reader.readLines(filename);
293-
return measurePerfFn('wordsPerLineWordList', () => _wordsPerLineWordList(lines, filename.toString(), options));
294-
}
295290

296-
function _wordsPerLineWordList(lines: Iterable<string>, filename: string, options: LoadOptions) {
297291
const words = pipe(
298292
lines,
299293
// Remove comments
@@ -302,21 +296,19 @@ function _wordsPerLineWordList(lines: Iterable<string>, filename: string, option
302296
opConcatMap((line) => line.split(/\s+/gu)),
303297
opFilter((word) => !!word),
304298
);
305-
return createSpellingDictionary(words, options.name, filename, options, true);
299+
return createSpellingDictionary(words, options.name, filename.href, options, true);
306300
}
307301

308302
async function loadSimpleWordList(reader: Reader, filename: URL, options: LoadOptions) {
309303
const lines = await reader.readLines(filename);
310-
return measurePerfFn('loadSimpleWordList', () =>
311-
createSpellingDictionary(lines, options.name, filename.href, options),
312-
);
304+
using _ = measurePerf('loadSimpleWordList');
305+
return createSpellingDictionary(lines, options.name, filename.href, options);
313306
}
314307

315308
async function loadTrie(reader: Reader, filename: URL, options: LoadOptions) {
316309
const content = await reader.read(filename);
317-
return measurePerfFn('loadTrie', () =>
318-
createSpellingDictionaryFromTrieFile(content, options.name, filename.href, options),
319-
);
310+
using _ = measurePerf('loadTrie');
311+
return createSpellingDictionaryFromTrieFile(content, options.name, filename.href, options);
320312
}
321313

322314
function toLines(content: string): string[] {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export { measurePerf, measurePerfEnd, measurePerfFn, measurePerfStart } from './performance.js';
21
export type { PerfTimer } from './timer.js';
32
export { createPerfTimer } from './timer.js';
3+
export { measurePerf } from '@cspell/cspell-performance-monitor';

packages/cspell-lib/src/lib/perf/performance.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 Jason Dent
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# CSpell Performance Monitor
2+
3+
Package: `@cspell/cspell-performance-monitor`
4+
5+
This is a library of methods used to measure performance within CSpell.
6+
7+
It uses the standard [Performance API - Web APIs](https://developer.mozilla.org/en-US/docs/Web/API/Performance_API)

0 commit comments

Comments
 (0)