Skip to content

Commit 2dcbb59

Browse files
committed
perf: lazy initialization of NodeVarRegistry
During extension initialization all containers with Node variable information were initialized eagerly, so it slows up vs code startup.
1 parent 54eae2a commit 2dcbb59

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

src/extension.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,8 @@ async function bootstrapExtensionCommand() {
460460
await vscode.window.showTextDocument(td);
461461
}
462462

463-
export function createPgVariablesView(context: vscode.ExtensionContext,
464-
nodeVars: vars.NodeVarRegistry) {
465-
const nodesView = new vars.PgVariablesViewProvider(nodeVars);
463+
export function createPgVariablesView(context: vscode.ExtensionContext) {
464+
const nodesView = new vars.PgVariablesViewProvider();
466465
const nodesViewName = Configuration.Views.NodePreviewTreeView;
467466
const treeDisposable = vscode.window.registerTreeDataProvider(nodesViewName,
468467
nodesView);
@@ -511,9 +510,10 @@ export function setupExtension(context: vscode.ExtensionContext) {
511510
}
512511

513512
function setupPgVariablesView(context: vscode.ExtensionContext) {
514-
const nodeVars = new vars.NodeVarRegistry();
515-
const pgvars = createPgVariablesView(context, nodeVars);
513+
const pgvars = createPgVariablesView(context);
516514

515+
/* TODO: unused - remove */
516+
const nodeVars = new vars.NodeVarRegistry();
517517
setupNodeTagFiles(context, nodeVars);
518518

519519
return pgvars;

src/variables.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -439,27 +439,27 @@ export class ExecContext {
439439
/**
440440
* Registry about NodeTag variables information
441441
*/
442-
nodeVarRegistry: NodeVarRegistry;
442+
nodeVarRegistry = new NodeVarRegistry();
443443

444444
/**
445445
* Registry with information of Special Members
446446
*/
447-
specialMemberRegistry: SpecialMemberRegistry;
447+
specialMemberRegistry = new SpecialMemberRegistry();
448448

449449
/**
450450
* Types of entries, that different HTAB store (dynahash.c)
451451
*/
452-
hashTableTypes: HashTableTypes;
452+
hashTableTypes = new HashTableTypes();
453453

454454
/**
455-
* Facade for debugger interface (TAP)
455+
* Cached properties for current step.
456456
*/
457-
debug: dbg.IDebuggerFacade;
457+
step = new StepContext();
458458

459459
/**
460-
* Cached properties for current step.
460+
* Facade for debugger interface (TAP)
461461
*/
462-
step: StepContext;
462+
debug: dbg.IDebuggerFacade;
463463

464464
/* Properties for current debug session */
465465
/**
@@ -554,12 +554,8 @@ export class ExecContext {
554554
*/
555555
canUseMacros = true;
556556

557-
constructor(nodeVarRegistry: NodeVarRegistry, debug: dbg.IDebuggerFacade) {
558-
this.nodeVarRegistry = nodeVarRegistry;
557+
constructor(debug: dbg.IDebuggerFacade) {
559558
this.debug = debug;
560-
this.specialMemberRegistry = new SpecialMemberRegistry();
561-
this.hashTableTypes = new HashTableTypes();
562-
this.step = new StepContext();
563559
}
564560

565561
async getCurrentFunctionName() {
@@ -5397,8 +5393,6 @@ export class PgVariablesViewProvider implements vscode.TreeDataProvider<Variable
53975393
*/
53985394
debug?: dbg.GenericDebuggerFacade;
53995395

5400-
constructor(private nodeVars: NodeVarRegistry) { }
5401-
54025396
/* https://code.visualstudio.com/api/extension-guides/tree-view#updating-tree-view-content */
54035397
private _onDidChangeTreeData = new vscode.EventEmitter<void>();
54045398
readonly onDidChangeTreeData = this._onDidChangeTreeData.event;
@@ -5510,7 +5504,7 @@ export class PgVariablesViewProvider implements vscode.TreeDataProvider<Variable
55105504
}
55115505

55125506
async createExecContext(frameId: number) {
5513-
const context = new ExecContext(this.nodeVars, this.getDebug());
5507+
const context = new ExecContext(this.getDebug());
55145508

55155509
/* Initialize using default builtin values */
55165510
const sm = context.specialMemberRegistry;
@@ -5542,7 +5536,7 @@ export class PgVariablesViewProvider implements vscode.TreeDataProvider<Variable
55425536
}
55435537

55445538
/* Initialize using configuration file - last, so user can override */
5545-
this.initializeExecContextFromConfig(context);
5539+
this.initializeExecContextFromConfig(context);
55465540

55475541
return context;
55485542
}

0 commit comments

Comments
 (0)