-
-
Notifications
You must be signed in to change notification settings - Fork 37
Optimizing performance for traversing stacks #3343
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
fc6ea0f
fix(flattenIO): optimizing performance for walking stack (1.8-19x).
RobinTail aab50b1
fix(hasCycle): optimizing traverse for performance.
RobinTail 17cede3
fix(Diagnostics): optimizing traverse of checkSchema() method for per…
RobinTail d4f5927
fix(fixReferences): optimizing traverse for performance.
RobinTail c753a10
fix(walkRouting): optimizing traverse for performance, O(1) read, sti…
RobinTail 60834a6
fix(zts): optimizing onTemplateLiteral for performance.
RobinTail fb85aa7
fix(onTemplateLiteral): naming, rm redundant copy.
RobinTail 4b5e4ad
FIX: replacing let+while with simpler for loop everywhere except zts …
RobinTail bb95ef4
fix(zts): avoiding negated increment in onTemplateLiteral::readText().
RobinTail f0e93d8
fix(lint): add rule to prohibit shifting.
RobinTail 0c846ad
fix(routing): linear handlers aggregation instead of shifting in init…
RobinTail c5e2df4
Test for in-depth first logic of walkRouting().
RobinTail 6e44628
nit: rm splice from eslint rule.
RobinTail dc0ca77
rm import from vitest in test.
RobinTail 396c11e
fix(test): rm redundant config option.
RobinTail 243e0c8
fix(test): using test.each to optimize setup and assertions.
RobinTail File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { bench, describe } from "vitest"; | ||
|
|
||
| const smallQueue = Array.from({ length: 5 }, (_, i) => ({ | ||
| id: i, | ||
| data: `item-${i}`, | ||
| })); | ||
| const mediumQueue = Array.from({ length: 20 }, (_, i) => ({ | ||
| id: i, | ||
| data: `item-${i}`, | ||
| })); | ||
| const largeQueue = Array.from({ length: 100 }, (_, i) => ({ | ||
| id: i, | ||
| data: `item-${i}`, | ||
| })); | ||
|
|
||
| const queues = [ | ||
| [smallQueue, "small (5)"], | ||
| [mediumQueue, "medium (20)"], | ||
| [largeQueue, "large (100)"], | ||
| ] as const; | ||
|
|
||
| describe.each(queues)("$1", (queue) => { | ||
| bench("shift() approach", () => { | ||
| const q = [...queue]; | ||
| while (q.length) q.shift(); | ||
| }); | ||
|
|
||
| bench("index approach", () => { | ||
| const q = [...queue]; | ||
| for (let idx = 0; idx < q.length; idx++) q[idx]; // eslint-disable-line @typescript-eslint/no-unused-expressions | ||
| }); | ||
|
|
||
| bench("pop() reverse", () => { | ||
| const q = [...queue].reverse(); | ||
| while (q.length) q.pop(); | ||
| }); | ||
|
|
||
| bench("forEach", () => { | ||
| const q = [...queue]; | ||
| q.forEach(() => {}); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
express-zod-api/tests/__snapshots__/routing-walker.spec.ts.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
|
||
| exports[`walkRouting() > should process endpoints in depth-first order 0 1`] = ` | ||
| [ | ||
| [ | ||
| "get", | ||
| "/v1/user/retrieve", | ||
| Endpoint {}, | ||
| ], | ||
| [ | ||
| "get", | ||
| "/v1/user/create", | ||
| Endpoint {}, | ||
| ], | ||
| [ | ||
| "get", | ||
| "/v1/record", | ||
| Endpoint {}, | ||
| ], | ||
| ] | ||
| `; | ||
|
|
||
| exports[`walkRouting() > should process endpoints in depth-first order 1 1`] = ` | ||
| [ | ||
| [ | ||
| "get", | ||
| "/a/b/c", | ||
| Endpoint {}, | ||
| ], | ||
| [ | ||
| "get", | ||
| "/a/d", | ||
| Endpoint {}, | ||
| ], | ||
| ] | ||
| `; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { defaultEndpointsFactory, Routing } from "../src"; | ||
| import { walkRouting } from "../src/routing-walker"; | ||
|
|
||
| describe("walkRouting()", () => { | ||
| const endpoint = defaultEndpointsFactory.buildVoid({ | ||
| handler: vi.fn(), | ||
| }); | ||
|
|
||
| const onEndpoint = vi.fn(); | ||
|
|
||
| afterEach(() => { | ||
| onEndpoint.mockClear(); | ||
| }); | ||
|
|
||
| test.each<Routing>([ | ||
| { | ||
| v1: { | ||
| user: { retrieve: endpoint, create: endpoint }, | ||
| record: endpoint, | ||
| }, | ||
| }, | ||
| { a: { b: { c: endpoint }, d: endpoint } }, | ||
| ])("should process endpoints in depth-first order %#", (routing) => { | ||
| walkRouting({ routing, config: { cors: false }, onEndpoint }); | ||
| expect(onEndpoint.mock.calls).toMatchSnapshot(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.