Skip to content
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

Pool some more nodes in test profile #360

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Conversation

jakebailey
Copy link
Member

@jakebailey jakebailey commented Feb 14, 2025

Profiling #275 netted some simple wins; a few new AST nodes to pool.

                                                             │   old.txt   │              new.txt               │
                                                             │   sec/op    │   sec/op     vs base               │
Parse/empty.ts/tsc-20                                          395.6n ± 1%   400.4n ± 1%  +1.21% (p=0.016 n=10)
Parse/empty.ts/server-20                                       397.4n ± 1%   401.1n ± 1%  +0.94% (p=0.009 n=10)
Parse/checker.ts/tsc-20                                        40.43m ± 1%   40.41m ± 1%       ~ (p=0.971 n=10)
Parse/checker.ts/server-20                                     41.26m ± 2%   41.15m ± 1%       ~ (p=0.393 n=10)
Parse/dom.generated.d.ts/tsc-20                                12.64m ± 1%   12.45m ± 2%  -1.52% (p=0.001 n=10)
Parse/dom.generated.d.ts/server-20                             18.38m ± 1%   18.09m ± 1%  -1.60% (p=0.000 n=10)
Parse/Herebyfile.mjs/tsc-20                                    669.0µ ± 1%   671.9µ ± 1%       ~ (p=0.165 n=10)
Parse/Herebyfile.mjs/server-20                                 664.0µ ± 1%   668.1µ ± 1%  +0.62% (p=0.019 n=10)
Parse/jsxComplexSignatureHasApplicabilityError.tsx/tsc-20      242.3µ ± 1%   243.3µ ± 1%       ~ (p=0.436 n=10)
Parse/jsxComplexSignatureHasApplicabilityError.tsx/server-20   366.4µ ± 1%   374.5µ ± 1%  +2.21% (p=0.000 n=10)
geomean                                                        547.1µ        548.4µ       +0.24%
                                                             │   old.txt    │                new.txt                │
                                                             │     B/op     │     B/op      vs base                 │
Parse/empty.ts/tsc-20                                            816.0 ± 0%     816.0 ± 0%       ~ (p=1.000 n=10) ¹
Parse/empty.ts/server-20                                         816.0 ± 0%     816.0 ± 0%       ~ (p=1.000 n=10) ¹
Parse/checker.ts/tsc-20                                        24.21Mi ± 0%   24.19Mi ± 0%  -0.09% (p=0.000 n=10)
Parse/checker.ts/server-20                                     24.39Mi ± 0%   24.37Mi ± 0%  -0.09% (p=0.000 n=10)
Parse/dom.generated.d.ts/tsc-20                                8.639Mi ± 0%   8.648Mi ± 0%  +0.11% (p=0.000 n=10)
Parse/dom.generated.d.ts/server-20                             11.00Mi ± 0%   11.01Mi ± 0%  +0.09% (p=0.000 n=10)
Parse/Herebyfile.mjs/tsc-20                                    428.2Ki ± 0%   429.5Ki ± 0%  +0.29% (p=0.000 n=10)
Parse/Herebyfile.mjs/server-20                                 428.0Ki ± 0%   429.3Ki ± 0%  +0.32% (p=0.000 n=10)
Parse/jsxComplexSignatureHasApplicabilityError.tsx/tsc-20      159.7Ki ± 0%   161.5Ki ± 0%  +1.12% (p=0.000 n=10)
Parse/jsxComplexSignatureHasApplicabilityError.tsx/server-20   236.7Ki ± 0%   238.5Ki ± 0%  +0.76% (p=0.000 n=10)
geomean                                                        439.9Ki        441.0Ki       +0.25%
¹ all samples are equal
                                                             │   old.txt   │                new.txt                │
                                                             │  allocs/op  │  allocs/op   vs base                  │
Parse/empty.ts/tsc-20                                           4.000 ± 0%    4.000 ± 0%        ~ (p=1.000 n=10) ¹
Parse/empty.ts/server-20                                        4.000 ± 0%    4.000 ± 0%        ~ (p=1.000 n=10) ¹
Parse/checker.ts/tsc-20                                        28.81k ± 0%   23.98k ± 0%  -16.76% (p=0.000 n=10)
Parse/checker.ts/server-20                                     29.43k ± 0%   24.60k ± 0%  -16.41% (p=0.000 n=10)
Parse/dom.generated.d.ts/tsc-20                                21.05k ± 0%   11.75k ± 0%  -44.20% (p=0.000 n=10)
Parse/dom.generated.d.ts/server-20                             27.98k ± 0%   18.68k ± 0%  -33.26% (p=0.000 n=10)
Parse/Herebyfile.mjs/tsc-20                                    1.304k ± 0%   1.255k ± 0%   -3.76% (p=0.000 n=10)
Parse/Herebyfile.mjs/server-20                                 1.304k ± 0%   1.255k ± 0%   -3.76% (p=0.000 n=10)
Parse/jsxComplexSignatureHasApplicabilityError.tsx/tsc-20       348.0 ± 0%    324.0 ± 0%   -6.90% (p=0.000 n=10)
Parse/jsxComplexSignatureHasApplicabilityError.tsx/server-20    614.0 ± 0%    590.0 ± 0%   -3.91% (p=0.000 n=10)
geomean                                                        1.112k         953.9       -14.26%
¹ all samples are equal                                     

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR aims to improve performance by pooling additional AST node types to reduce object allocations. Key changes include:

  • Adding new pools for InterfaceDeclaration, KeywordExpression, MethodSignatureDeclaration, NumericLiteral, and UnionTypeNode.
  • Updating the corresponding New* functions to use the new pools.
  • Modifying node creation in the AST to leverage pooled instances for improved memory reuse.

Reviewed Changes

File Description
internal/ast/ast.go Introduces new node pools and updates node creation functions to use pooling

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

internal/ast/ast.go:5357

  • Verify that the UnionTypeNode object returned from the pool is properly cleared of any prior state. Explicitly resetting fields might be necessary to guarantee correct behavior.
data := f.unionTypeNodePool.New()

Tip: Copilot code review supports C#, Go, Java, JavaScript, Markdown, Python, Ruby and TypeScript, with more languages coming soon. Learn more

Copy link

@S-YOU S-YOU left a comment

Choose a reason for hiding this comment

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

14% less allocations, looks like it worth it.

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.

None yet

2 participants