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

perf(types): define ParamKey simply #3837

Merged
merged 1 commit into from
Jan 19, 2025
Merged

Conversation

yusukebe
Copy link
Member

ParamKeyName is unnecessary since it is used only in ParamKey. Removing it introduces decreasing in Instantiations for TypeScript.

The author should do the following, if applicable

  • Add tests
  • Run tests
  • bun run format:fix && bun run lint:fix to format the code
  • Add TSDoc/JSDoc to document the code

This comment has been minimized.

Copy link

codecov bot commented Jan 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.31%. Comparing base (502709f) to head (f2b8d45).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #3837    +/-   ##
========================================
  Coverage   91.31%   91.31%            
========================================
  Files         161      161            
  Lines       10240    10240            
  Branches     2997     2897   -100     
========================================
  Hits         9351     9351            
  Misses        888      888            
  Partials        1        1            

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

This comment has been minimized.

Copy link

Bundle size check

main (502709f) #3837 (a60565a) +/-
Bundle Size (B) 18,771B 18,771B 0B
Bundle Size (KB) 18.33K 18.33K 0K

Compiler Diagnostics

main (502709f) #3837 (a60565a) +/-
Files 257 257 0
Lines 115,047 115,045 -2
Identifiers 112,032 112,028 -4
Symbols 243,516 243,514 -2
Types 204,790 204,788 -2
Instantiations 3,044,415 3,044,389 -26
Memory used 420,391K 426,207K 5,816K
I/O read 0.03s 0.02s -0.01s
I/O write 0s 0s 0s
Parse time 0.68s 0.66s -0.02s
Bind time 0.26s 0.31s 0.05s
Check time 5.49s 5.17s -0.32s
Emit time 0s 0s 0s
Total time 6.43s 6.14s -0.29s

Reported by octocov

@yusukebe
Copy link
Member Author

The Memory used in the comment from CI increased. However, the changes depend on the environment and conditions, and in my environment, there were no big changes.

@yusukebe
Copy link
Member Author

@EdamAme-x

Can you review this too?

Copy link
Contributor

@EdamAme-x EdamAme-x left a comment

Choose a reason for hiding this comment

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

I checked performance on Bun and found a 2x improvement.

runtime: bun 1.1.34 (x64-win32)

benchmark                   avg (min … max) p75 / p99    (min … top 1%)
------------------------------------------- -------------------------------
Before                       632.50 µs/iter 634.60 µs  █
                      (307.70 µs … 4.10 ms)   3.01 ms  █
                    (  0.00  b …   2.30 gb)  88.40 mb ███▄▃▂▃▂▂▂▁▁▁▁▁▁▁▁▁▁▁
After                        345.72 µs/iter 340.70 µs  █
                      (249.90 µs … 3.53 ms)   1.23 ms ▂█
                    (  0.00  b … 984.00 mb)  26.60 mb ██▇▄▃▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

Before

type ParamKeyName<NameWithPattern> = NameWithPattern extends `${infer Name}{${infer Rest}`
  ? Rest extends `${infer _Pattern}?`
    ? `${Name}?`
    : Name
  : NameWithPattern;

type ParamKey<Component> = Component extends `:${infer NameWithPattern}`
  ? ParamKeyName<NameWithPattern>
  : never;

export type TestCases = [
  ParamKey<":user{id}">,
  ParamKey<":post{id}">,
  ParamKey<":comment{id}?">,
  ParamKey<":user">,
  ParamKey<":post">,
  ParamKey<":comment">,
];

After

type ParamKey2<Component> = Component extends `:${infer NameWithPattern}`
  ? NameWithPattern extends `${infer Name}{${infer Rest}`
    ? Rest extends `${infer _Pattern}?`
      ? `${Name}?`
      : Name
    : NameWithPattern
  : never;

export type TestCases2 = [
  ParamKey2<":user{id}">,
  ParamKey2<":post{id}">,
  ParamKey2<":comment{id}?">,
  ParamKey2<":user">,
  ParamKey2<":post">,
  ParamKey2<":comment">,
];

@yusukebe
Copy link
Member Author

@EdamAme-x Thaaank!

@yusukebe yusukebe merged commit ac4d42c into main Jan 19, 2025
16 checks passed
@yusukebe yusukebe deleted the perf/remove-param-key-name branch January 19, 2025 06:51
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