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

Improve codegen bundle size and typings #2999

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

Conversation

matthieusieben
Copy link
Contributor

@matthieusieben matthieusieben commented Nov 14, 2024

This PR is the first of a 3 step changes aimed at improving typing in the atproto repo:

Note

When reviewing, "codegen" commits can be ignored as they only contain generated code changes.

@matthieusieben matthieusieben force-pushed the msi/lex-gen-optimization branch 3 times, most recently from 2abd90e to ef8af3f Compare November 14, 2024 15:26
@matthieusieben matthieusieben changed the title Improve codegen bundle size Improve codegen bundle size and typings Nov 14, 2024
@matthieusieben matthieusieben force-pushed the msi/lex-gen-optimization branch 2 times, most recently from bebca0e to 0bea135 Compare November 14, 2024 16:05
@matthieusieben matthieusieben force-pushed the msi/lex-gen-optimization branch from 0bea135 to 02ddb9a Compare November 15, 2024 07:57
@matthieusieben matthieusieben force-pushed the msi/lex-gen-optimization branch from 02ddb9a to 1a337a2 Compare November 15, 2024 10:52
Makefile Outdated Show resolved Hide resolved
packages/syntax/src/tid.ts Outdated Show resolved Hide resolved
packages/lexicon/src/types.ts Show resolved Hide resolved
Comment on lines 21 to 25
: // $type === `${id}#${hash}`
$type.length === id.length + 1 + hash.length &&
$type[id.length] === '#' &&
$type.startsWith(id) &&
$type.endsWith(hash))
Copy link
Collaborator

Choose a reason for hiding this comment

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

For workloads where check$type() is usually true it's not clear to me that this is going to have the intended effect of a performance improvement over the simpler version. Or is the idea specifically to avoid allocating the additional string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did it mainly for the string allocation. The optimization in the false case is a bonus.

https://jsbench.me/l6m46vgr4q/1

  • true case is 4% faster
  • false case is > 50% faster

tested on FF

@matthieusieben matthieusieben force-pushed the msi/lex-gen-optimization branch from 2714235 to 617d86c Compare December 2, 2024 10:32
@matthieusieben matthieusieben force-pushed the msi/lex-gen-optimization branch from 6e398be to 17b3081 Compare December 18, 2024 09:39
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.

3 participants