-
Notifications
You must be signed in to change notification settings - Fork 122
perf(util-endpoints): reduce temporary object allocations #1957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
f86da38
67e2fbc
d1b0cfd
53c7b2c
6a00f07
dfad86b
40171a4
d87e495
6e1c3a8
78eb850
9a97c49
aa81904
4d49292
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@smithy/util-endpoints": patch | ||
| --- | ||
|
|
||
| Reduce temporary object allocations |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,22 +4,21 @@ import { evaluateCondition } from "./evaluateCondition"; | |
|
|
||
| export const evaluateConditions = (conditions: ConditionObject[] = [], options: EvaluateOptions) => { | ||
| const conditionsReferenceRecord: Record<string, FunctionReturn> = {}; | ||
| const conditionOptions: EvaluateOptions = { | ||
| ...options, | ||
| referenceRecord: { ...options.referenceRecord }, | ||
| }; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it safe to use Why I think it might be safe: options object lifecycle is one endpoint resolution, and this is all synchronous code...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
|
||
| for (const condition of conditions) { | ||
| const { result, toAssign } = evaluateCondition(condition, { | ||
| ...options, | ||
| referenceRecord: { | ||
| ...options.referenceRecord, | ||
| ...conditionsReferenceRecord, | ||
| }, | ||
| }); | ||
|
trivikr marked this conversation as resolved.
|
||
| const { result, toAssign } = evaluateCondition(condition, conditionOptions); | ||
|
|
||
| if (!result) { | ||
| return { result }; | ||
| } | ||
|
|
||
| if (toAssign) { | ||
| conditionsReferenceRecord[toAssign.name] = toAssign.value; | ||
| conditionOptions.referenceRecord[toAssign.name] = toAssign.value; | ||
| options.logger?.debug?.(`${debugId} assign: ${toAssign.name} := ${toDebugString(toAssign.value)}`); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,13 +27,13 @@ export const evaluateEndpointRule = ( | |
|
|
||
| options.logger?.debug?.(`${debugId} Resolving endpoint from template: ${toDebugString(endpoint)}`); | ||
|
|
||
| return { | ||
| ...(headers != undefined && { | ||
| headers: getEndpointHeaders(headers, endpointRuleOptions), | ||
| }), | ||
| ...(properties != undefined && { | ||
| properties: getEndpointProperties(properties, endpointRuleOptions), | ||
| }), | ||
| url: getEndpointUrl(url, endpointRuleOptions), | ||
| }; | ||
| const endpointToReturn: EndpointV2 = { url: getEndpointUrl(url, endpointRuleOptions) }; | ||
| if (headers != undefined) { | ||
|
trivikr marked this conversation as resolved.
Outdated
|
||
| endpointToReturn.headers = getEndpointHeaders(headers, endpointRuleOptions); | ||
| } | ||
| if (properties != undefined) { | ||
| endpointToReturn.properties = getEndpointProperties(properties, endpointRuleOptions); | ||
| } | ||
|
|
||
| return endpointToReturn; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.