Skip to content

Commit

Permalink
fix: Performance - only serialize config if in debug mode (#2640)
Browse files Browse the repository at this point in the history
* fix: Performance - only serialize config if in debug mode
* remove unused comment-json
  • Loading branch information
Jason3S committed Apr 1, 2022
1 parent 5f07225 commit d16c4f9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
10 changes: 9 additions & 1 deletion packages/cspell-lib/src/Settings/DictionarySettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ export function isDictionaryDefinitionInternal(
return def instanceof _DictionaryDefinitionInternalWithSource;
}

type DDI = Omit<RequireOptional<DictionaryDefinitionInternalWithSource>, '__source' | 'weightMap' | 'toJSON'>;

class _DictionaryDefinitionInternalWithSource implements DictionaryDefinitionInternalWithSource {
private _weightMap: WeightMap | undefined;
readonly name: string;
Expand All @@ -129,6 +131,7 @@ class _DictionaryDefinitionInternalWithSource implements DictionaryDefinitionInt
readonly useCompounds?: boolean;
readonly noSuggest?: boolean;
readonly scope?: CustomDictionaryScope | CustomDictionaryScope[];
private ddi: DDI;
constructor(def: DictionaryDefinition, readonly __source: string) {
// this bit of assignment is to have the compiler help use if any new fields are added.
const defAll: DictDef = def;
Expand All @@ -150,7 +153,7 @@ class _DictionaryDefinitionInternalWithSource implements DictionaryDefinitionInt

const r = resolveFile(filePath, defaultPath);

const ddi: Omit<RequireOptional<DictionaryDefinitionInternalWithSource>, '__source' | 'weightMap'> = {
const ddi: DDI = {
name,
file: undefined,
path: r.filename,
Expand All @@ -165,6 +168,7 @@ class _DictionaryDefinitionInternalWithSource implements DictionaryDefinitionInt
};

Object.assign(this, clean(ddi));
this.ddi = ddi;
this.name = ddi.name;
this.file = ddi.file;
this.path = ddi.path;
Expand All @@ -176,4 +180,8 @@ class _DictionaryDefinitionInternalWithSource implements DictionaryDefinitionInt
get weightMap() {
return this._weightMap;
}

toJSON() {
return this.ddi;
}
}
1 change: 0 additions & 1 deletion packages/cspell/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/cspell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
"@cspell/cspell-pipe": "^5.19.3",
"chalk": "^4.1.2",
"commander": "^9.1.0",
"comment-json": "^4.2.2",
"cspell-gitignore": "^5.19.3",
"cspell-glob": "^5.19.3",
"cspell-lib": "^5.19.3",
Expand Down
11 changes: 7 additions & 4 deletions packages/cspell/src/lint/lint.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { isAsyncIterable, opFilter, pipeAsync, pipeSync } from '@cspell/cspell-pipe';
import type { CSpellReporter, CSpellSettings, Glob, Issue, RunResult, TextDocumentOffset } from '@cspell/cspell-types';
import { MessageTypes } from '@cspell/cspell-types';
import * as commentJson from 'comment-json';
import { findRepoRoot, GitIgnore } from 'cspell-gitignore';
import { GlobMatcher, type GlobMatchOptions, type GlobPatternNormalized, type GlobPatternWithRoot } from 'cspell-glob';
import type { Logger, ValidationIssue } from 'cspell-lib';
import * as cspell from 'cspell-lib';
import * as path from 'path';
import { format } from 'util';
import { URI } from 'vscode-uri';
import { opFilter, isAsyncIterable, pipeAsync, pipeSync } from '@cspell/cspell-pipe';
import type { CSpellLintResultCache } from '../util/cache';
import { calcCacheSettings, createCache, CreateCacheSettings } from '../util/cache';
import { CheckFailed, toApplicationError, toError } from '../util/errors';
Expand Down Expand Up @@ -100,8 +99,12 @@ export async function runLint(cfg: LintRequest): Promise<RunResult> {

result.configErrors += await reportConfigurationErrors(config);

const debugCfg = { config: { ...config, source: null }, source: spellResult.localConfigFilepath };
reporter.debug(commentJson.stringify(debugCfg, undefined, 2));
if (cfg.options.debug) {
const { id: _id, name: _name, ...cfg } = config;
const debugCfg = { config: { ...cfg, source: null }, source: spellResult.localConfigFilepath };
reporter.debug(JSON.stringify(debugCfg, undefined, 2));
}

const elapsed = result.elapsedTimeMs / 1000.0;
const dictionaries = config.dictionaries || [];
reporter.info(
Expand Down

0 comments on commit d16c4f9

Please sign in to comment.