Skip to content

perf(util-endpoints): reduce temporary object allocations#1957

Merged
trivikr merged 13 commits intomainfrom
remove-object-allocation-evaluate-condition
Apr 16, 2026
Merged

perf(util-endpoints): reduce temporary object allocations#1957
trivikr merged 13 commits intomainfrom
remove-object-allocation-evaluate-condition

Conversation

@trivikr
Copy link
Copy Markdown
Contributor

@trivikr trivikr commented Apr 14, 2026

Issue

Internal JS-6645

Description

Remove rest spread destructuring that created a new object on every call, and replace conditional spread in the return with an early return branch to avoid temporary object allocation.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@trivikr trivikr requested a review from a team as a code owner April 14, 2026 21:44
@trivikr trivikr changed the title perf(util-endpoints): reduce allocations in evaluateCondition perf(util-endpoints): reduce object allocations Apr 14, 2026
@trivikr trivikr changed the title perf(util-endpoints): reduce object allocations perf(util-endpoints): reduce temporary object allocations Apr 14, 2026
@trivikr trivikr force-pushed the remove-object-allocation-evaluate-condition branch from b96ce29 to 6a00f07 Compare April 14, 2026 22:47
Comment thread packages/util-endpoints/src/utils/evaluateConditions.ts
@trivikr trivikr requested a review from kuhe April 15, 2026 01:10
@trivikr trivikr force-pushed the remove-object-allocation-evaluate-condition branch from ccc8015 to 78eb850 Compare April 15, 2026 07:23
const conditionOptions: EvaluateOptions = {
...options,
referenceRecord: { ...options.referenceRecord },
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it safe to use options all the way through with no copying?

Why I think it might be safe: options object lifecycle is one endpoint resolution, and this is all synchronous code...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll avoid modifying options, as it might create issues in future. It can be tested in a separate PR.

Comment thread packages/util-endpoints/src/types/shared.ts Outdated
Comment thread packages/util-endpoints/src/utils/evaluateCondition.ts
Comment thread packages/util-endpoints/src/utils/evaluateConditions.ts Outdated
Comment thread packages/util-endpoints/src/utils/evaluateEndpointRule.ts Outdated
endpointToReturn.properties = getEndpointProperties(properties, endpointRuleOptions);
}

return endpointToReturn;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unlikely, but does the call order matter for exception handling?

the old code called getEndpointUrl last.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the previous code would have thrown exceptions from getEndpointHeaders and getEndpointProperties before those from getEndpointUrl.

It should be okay though.

...options,
referenceRecord: { ...options.referenceRecord, ...referenceRecord },
});
const treeRuleOptions = referenceRecord
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the more code I (re-)read, the more I think options is safe to mutate

@trivikr trivikr merged commit 449ba5a into main Apr 16, 2026
15 checks passed
@trivikr trivikr deleted the remove-object-allocation-evaluate-condition branch April 16, 2026 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants