Skip to content

Commit 6902aae

Browse files
authored
fix: incremental Performance Degradation with session.customRequest("variables") Calls (#2120)
Fixes #2119
1 parent 4e9f6b8 commit 6902aae

File tree

1 file changed

+37
-29
lines changed

1 file changed

+37
-29
lines changed

src/adapter/variableStore.ts

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -428,20 +428,8 @@ class VariableContext {
428428
}
429429

430430
let variable: Variable | undefined;
431-
if (
432-
p.name === '[[FunctionLocation]]'
433-
&& p.value
434-
&& (p.value.subtype as string) === 'internal#location'
435-
) {
436-
variable = this.createVariable(
437-
FunctionLocationVariable,
438-
{
439-
name: p.name,
440-
presentationHint: { visibility: 'internal', attributes: ['readOnly'] },
441-
sortOrder: SortOrder.Internal,
442-
},
443-
p.value,
444-
);
431+
if (isFunctionLocation(p)) {
432+
variable = this.createFunctionLocationVariable(p);
445433
} else if (p.value !== undefined) {
446434
variable = this.createVariableByType(
447435
{
@@ -461,6 +449,18 @@ class VariableContext {
461449
return flatten(await Promise.all(properties));
462450
}
463451

452+
public createFunctionLocationVariable(p: FunctionLocationDescriptor) {
453+
return this.createVariable(
454+
FunctionLocationVariable,
455+
{
456+
name: p.name,
457+
presentationHint: { visibility: 'internal', attributes: ['readOnly'] },
458+
sortOrder: SortOrder.Internal,
459+
},
460+
p.value,
461+
);
462+
}
463+
464464
private async createPropertyVar(
465465
p: AnyPropertyDescriptor,
466466
owner: Cdp.Runtime.RemoteObject,
@@ -971,16 +971,19 @@ class NodeVariable extends Variable {
971971
}
972972

973973
class FunctionVariable extends ObjectVariable {
974-
private readonly baseChildren = once(() => super.getChildren({ variablesReference: this.id }));
975-
976974
public override async toDap(previewContext: PreviewContextType): Promise<Dap.Variable> {
977-
const [dap, children] = await Promise.all([
975+
const [dap, props] = await Promise.all([
978976
super.toDap(previewContext),
979-
this.baseChildren(),
977+
this.context.cdp.Runtime.getProperties({
978+
objectId: this.remoteObject.objectId!,
979+
ownProperties: true,
980+
nonIndexedPropertiesOnly: true,
981+
}),
980982
]);
981983

982-
if (children.some(c => c instanceof FunctionLocationVariable)) {
983-
dap.valueLocationReference = this.id;
984+
const location = props?.internalProperties?.find(isFunctionLocation);
985+
if (location) {
986+
dap.valueLocationReference = this.context.createFunctionLocationVariable(location).id;
984987
}
985988

986989
return dap;
@@ -1580,15 +1583,8 @@ export class VariableStore {
15801583
}
15811584

15821585
public async getLocations(variablesReference: number): Promise<Cdp.Debugger.Location> {
1583-
const container = this.vars.get(variablesReference);
1584-
if (!container) {
1585-
throw errors.locationNotFound();
1586-
}
1587-
1588-
// note: is actually free because the container will have cached its children
1589-
const children = await container.getChildren({ variablesReference });
1590-
const locationVar = children.find(isInstanceOf(FunctionLocationVariable));
1591-
if (!locationVar) {
1586+
const locationVar = this.vars.get(variablesReference);
1587+
if (!locationVar || !(locationVar instanceof FunctionLocationVariable)) {
15921588
throw errors.locationNotFound();
15931589
}
15941590

@@ -1630,3 +1626,15 @@ function errorFromException(details: Cdp.Runtime.ExceptionDetails): Dap.Error {
16301626
|| details.text;
16311627
return errors.createUserError(message);
16321628
}
1629+
1630+
type FunctionLocationDescriptor = Cdp.Runtime.InternalPropertyDescriptor & {
1631+
value: Cdp.Debugger.Location;
1632+
};
1633+
1634+
function isFunctionLocation(
1635+
p: Cdp.Runtime.InternalPropertyDescriptor,
1636+
): p is FunctionLocationDescriptor {
1637+
return p.name === '[[FunctionLocation]]'
1638+
&& !!p.value
1639+
&& (p.value.subtype as string) === 'internal#location';
1640+
}

0 commit comments

Comments
 (0)