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: reduce bundle size for Object.keys(import.meta.glob(...)) #18666

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

Conversation

btea
Copy link
Collaborator

@btea btea commented Nov 14, 2024

Description

close #18662

@sapphi-red
Copy link
Member

I think we should optimize Object.keys(import.meta.glob / Object.values(import.meta.glob instead of introducing a new query so that users won't need to think about it.
It would be great if rollup or a minifier can optimize this case, but I guess it's easier to do it on our side.

@btea
Copy link
Collaborator Author

btea commented Nov 19, 2024

Thanks for your suggestion. But maybe we just need to optimize Object.keys(import.meta.glob, and Object.values(import.meta.glob should follow the original logic.

@btea
Copy link
Collaborator Author

btea commented Nov 20, 2024

Thanks for the review, the code has been updated.

@sapphi-red sapphi-red changed the title feat: import.meta.glob support query ?nocontent perf: reduce bundle size for Object.keys(import.meta.glob(...)) Nov 20, 2024
@sapphi-red sapphi-red added the p2-nice-to-have Not breaking anything but nice to have (priority) label Nov 20, 2024
Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

The linked issue also requests supporting Object.values, should we not close the issue until that's supported?

@btea
Copy link
Collaborator Author

btea commented Nov 20, 2024

As far as I understand, Object.values(import.meta.glob('')) can only follow the normal parsing process to get the corresponding object and then get the corresponding values. Are there any other optimization methods here?

@bluwy
Copy link
Member

bluwy commented Nov 20, 2024

I was thinking that the keys could be minimized, like "0" or "1" instead of paths like "./src/foo.png".

I was also thinking there could be a further optimization in the future where we replace the Object.keys() or Object.values() altogether and directly replace them as an array, but that's harder and we can leave that for later. So if the PR is more of a stop-gap optimization for Object.keys(), maybe we can also do a stop-gap for Object.values().

@btea
Copy link
Collaborator Author

btea commented Nov 20, 2024

@bluwy Thanks for the detailed instructions. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize bundle for Object.keys(import.meta.glob()) and Object.values(import.meta.glob())
3 participants