hono icon indicating copy to clipboard operation
hono copied to clipboard

perf: make functions common for reduce code size

Open yusukebe opened this issue 8 months ago • 9 comments

This PR reduces the bundle code size with common functions that can't be minified with the bundler.

Created the following functions:

  • createEmptyRecord
  • createResponse

And applied to the core files. I think we don't have to optimize unrelated to the core like under src/middleware now.

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

yusukebe avatar Apr 25 '25 09:04 yusukebe

Bundle size check

main (15a83b1) #4111 (8dd7335) +/-
Bundle Size (B) 18,904B 18,554B -350B
Bundle Size (KB) 18.46K 18.12K -0.34K

Compiler Diagnostics

main (15a83b1) #4111 (8dd7335) +/-
Files 261 262 1
Lines 116,434 116,446 12
Identifiers 114,428 114,427 -1
Symbols 303,852 303,870 18
Types 214,828 214,830 2
Instantiations 3,091,594 3,091,594 0
Memory used 445,293K 454,562K 9,269K
I/O read 0.03s 0.02s -0.01s
I/O write 0s 0s 0s
Parse time 0.66s 0.64s -0.02s
Bind time 0.28s 0.28s 0s
Check time 5.84s 5.64s -0.2s
Emit time 0s 0s 0s
Total time 6.78s 6.56s -0.22s

Reported by octocov

github-actions[bot] avatar Apr 25 '25 09:04 github-actions[bot]

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 91.66%. Comparing base (4eb7979) to head (0fcb7ff).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4111      +/-   ##
==========================================
+ Coverage   91.31%   91.66%   +0.35%     
==========================================
  Files         168      169       +1     
  Lines       10790    10692      -98     
  Branches     3067     3055      -12     
==========================================
- Hits         9853     9801      -52     
+ Misses        936      890      -46     
  Partials        1        1              

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Apr 25 '25 09:04 codecov[bot]

Bundle size check

main (c277c75) #4111 (117d4ff) +/-
Bundle Size (B) 18,933B 18,583B -350B
Bundle Size (KB) 18.49K 18.15K -0.34K

Compiler Diagnostics

main (c277c75) #4111 (117d4ff) +/-
Files 261 262 1
Lines 116,438 116,450 12
Identifiers 114,433 114,432 -1
Symbols 303,855 303,873 18
Types 214,832 214,834 2
Instantiations 3,091,594 3,091,594 0
Memory used 444,751K 444,586K -165K
I/O read 0.02s 0.02s 0s
I/O write 0s 0s 0s
Parse time 0.67s 0.68s 0.01s
Bind time 0.28s 0.29s 0.01s
Check time 5.77s 5.62s -0.15s
Emit time 0s 0s 0s
Total time 6.72s 6.58s -0.14s

Reported by octocov

github-actions[bot] avatar Apr 28 '25 10:04 github-actions[bot]

Bundle size check

main (4eb7979) #4111 (95cbc44) +/-
Bundle Size (B) 18,979B 18,629B -350B
Bundle Size (KB) 18.53K 18.19K -0.34K

Compiler Diagnostics (tsc)

main (4eb7979) #4111 (95cbc44) +/-
Files 261 262 1
Lines 116,440 116,452 12
Identifiers 114,437 114,436 -1
Symbols 259,899 259,917 18
Types 162,567 162,569 2
Instantiations 3,039,293 3,039,293 0
Memory used 272,781K 273,082K 301K
I/O read 0.03s 0.02s -0.01s
I/O write 0s 0s 0s
Parse time 0.68s 0.65s -0.03s
Bind time 0.28s 0.28s 0s
Check time 4.04s 3.78s -0.26s
Emit time 0s 0s 0s
Total time 5s 4.72s -0.28s

Reported by octocov

github-actions[bot] avatar May 31 '25 20:05 github-actions[bot]

Bundle size check

main (4eb7979) #4111 (95cbc44) +/-
Bundle Size (B) 18,979B 18,629B -350B
Bundle Size (KB) 18.53K 18.19K -0.34K

Compiler Diagnostics (typescript-go)

main (4eb7979) #4111 (95cbc44) +/-
Files 231 232 1
Lines 106,339 106,351 12
Identifiers 106,177 106,176 -1
Symbols 371,550 351,269 -20,281
Types 292,987 286,488 -6,499
Instantiations 3,568,485 3,545,794 -22,691
Memory used 229,637K 221,216K -8,421K
Memory allocs 10,003,491 9,944,001 -59,490
Parse time 0.071s 0.066s -0.005s
Bind time 0.031s 0.02s -0.011s
Check time 1.391s 1.478s 0.087s
Emit time 0s 0s 0s
Total time 1.504s 1.565s 0.061s

Reported by octocov

github-actions[bot] avatar May 31 '25 20:05 github-actions[bot]

Hey @EdamAme-x

Do you think merging this PR is worth it? If so, please review this.

yusukebe avatar May 31 '25 20:05 yusukebe

Hello @usualoma !

What do you think of this optimization?

yusukebe avatar Jun 08 '25 03:06 yusukebe

Hi @yusukebe. Thank you!

If you ask me if it's really necessary, I'd say it's a gray area, but I don't think it will reduce maintainability, so it's fine.

usualoma avatar Jun 08 '25 04:06 usualoma

@usualoma

Thanks! I also think this is a "gray area". I'll decide whether to merge later.

yusukebe avatar Jun 09 '25 10:06 yusukebe