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

Only lookup exact match if there are no startsWith matches #7

Merged
merged 3 commits into from
Dec 24, 2023

Conversation

avioli
Copy link
Contributor

@avioli avioli commented Dec 3, 2023

Optimize use of calls that doesn't need to run until they do - like move exact querySelector to the else clause and remove Array.from, since Node Lists have forEach method built-in.

This shaves off 2 bytes from bundle and minified sizes and 4-5 bytes when gzipped:

Before

┌──────────────────────────────┐
│ Destination: dist/current.js │
│ Bundle Size:  452 B          │
│ Minified Size:  451 B        │
│ Gzipped Size:  314 B         │
└──────────────────────────────┘
┌──────────────────────────────────┐
│ Destination: dist/current.umd.js │
│ Bundle Size:  684 B              │
│ Minified Size:  683 B            │
│ Gzipped Size:  422 B             │
└──────────────────────────────────┘

After

┌──────────────────────────────┐
│ Destination: dist/current.js │
│ Bundle Size:  450 B          │
│ Minified Size:  449 B        │
│ Gzipped Size:  309 B         │
└──────────────────────────────┘
┌──────────────────────────────────┐
│ Destination: dist/current.umd.js │
│ Bundle Size:  682 B              │
│ Minified Size:  681 B            │
│ Gzipped Size:  418 B             │
└──────────────────────────────────┘

Optimize use of calls that doesn't need to run until they do.
@avioli
Copy link
Contributor Author

avioli commented Dec 3, 2023

Oh... apparently I was able to optimize it even further, by removing the if block as well as return early from startsWith block:

┌──────────────────────────────┐
│ Destination: dist/current.js │
│ Bundle Size:  433 B          │
│ Minified Size:  432 B        │
│ Gzipped Size:  304 B         │
└──────────────────────────────┘
┌──────────────────────────────────┐
│ Destination: dist/current.umd.js │
│ Bundle Size:  665 B              │
│ Minified Size:  664 B            │
│ Gzipped Size:  413 B             │
└──────────────────────────────────┘

Edit: Above stats are wrong, since they are from a broken build, that was fixed via the below force-push changeset.

@marcoroth
Copy link
Owner

Thank you for this contribution, @avioli!

This looks good, would you mind checking the failing tests so we can get this merged in!

@avioli
Copy link
Contributor Author

avioli commented Dec 18, 2023

Fixed @marcoroth, but for the life of me I cannot get that 433 B bundle size anymore... although I expected it to go down!

┌──────────────────────────────┐
│ Destination: dist/current.js │
│ Bundle Size:  444 B          │
│ Minified Size:  443 B        │
│ Gzipped Size:  308 B         │
└──────────────────────────────┘
┌──────────────────────────────────┐
│ Destination: dist/current.umd.js │
│ Bundle Size:  676 B              │
│ Minified Size:  675 B            │
│ Gzipped Size:  418 B             │
└──────────────────────────────────┘

Weirdly the Gzipped size varies with ±1 byte, based on the NodeJS version - I am running v18.12.1 (as per .node-version), but the tests were running on v18.19.0.

Edit: I think I know where the 433 B figure comes from - it was from a build, which was broken, that I fixed, then force-pushed.

Copy link
Owner

@marcoroth marcoroth left a comment

Choose a reason for hiding this comment

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

Thanks @avioli!

@marcoroth marcoroth merged commit b7660b6 into marcoroth:main Dec 24, 2023
6 checks passed
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