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(es/minifier): Make analyzer not call collect_infects_from recursively #9924

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

Conversation

kdy1
Copy link
Member

@kdy1 kdy1 commented Jan 22, 2025

Description:

We don't need to make time complexity non-linear by recursively visiting the effects of infection. Instead, suppose we stop the infection analyzer when the usage analyzer invokes the infection analyzer. In that case, we will have practically identical analysis results because the points are named using an id, and it points to all the infections that occurred by referencing the id.

@kdy1 kdy1 added this to the Planned milestone Jan 22, 2025
@kdy1 kdy1 self-assigned this Jan 22, 2025
Copy link

changeset-bot bot commented Jan 22, 2025

⚠️ No Changeset found

Latest commit: d21d068

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@kdy1
Copy link
Member Author

kdy1 commented Jan 22, 2025

cc @CPunisher Do you have an idea for better caching? *const Function does not look good to me.

@CPunisher
Copy link
Member

CPunisher commented Jan 23, 2025

cc @CPunisher Do you have an idea for better caching? *const Function does not look good to me.

The point is to determine an unique id for a function node. Maybe Ident, Span...Since we don't have node id, we may need to find the unique id based on the context.

BTW does it handle a node many times?

@kdy1
Copy link
Member Author

kdy1 commented Jan 23, 2025

@CPunisher Yeap. I wrote about them in #9927.

While visiting nodes for usage analysis, it calls collect_infects_from on the node, but while recursing into a node from the usage analyzer, it calls collect_infects_from on a child node again.

@CPunisher
Copy link
Member

@CPunisher Yeap. I wrote about them in #9927.

While visiting nodes for usage analysis, it calls collect_infects_from on the node, but while recursing into a node from the usage analyzer, it calls collect_infects_from on a child node again.

I see. If it is hard to cache the result, can we avoid repeated analysis? That means we can stop collect_infects_from going deeper since we know we will handle inner nodes later.

@kdy1
Copy link
Member Author

kdy1 commented Jan 24, 2025

That's ideal, but I'm not sure about the way. I'm still investigating. Expected gain is so big but actually it's just an issue of my skill level.

@kdy1 kdy1 force-pushed the min-cache-infects branch from c2479cd to 74393af Compare January 26, 2025 22:49
@kdy1 kdy1 changed the title perf(es/minifier): Add cache for collect_infects_from perf(es/minifier): Make usage anayzer not recursively call collect_infects_from Jan 26, 2025
@kdy1 kdy1 requested a review from CPunisher January 26, 2025 23:05
@kdy1 kdy1 marked this pull request as ready for review January 26, 2025 23:06
@kdy1 kdy1 requested a review from a team as a code owner January 26, 2025 23:06
kodiakhq[bot]
kodiakhq bot previously approved these changes Jan 26, 2025
@kdy1 kdy1 requested a review from a team as a code owner January 26, 2025 23:06
kodiakhq[bot]
kodiakhq bot previously approved these changes Jan 26, 2025
@kdy1
Copy link
Member Author

kdy1 commented Jan 26, 2025

@CPunisher I think I managed to find something close to not recursively calling them. But I want to ensure that my assumption about usage analyzer, and actual code is correct.

@kdy1 kdy1 changed the title perf(es/minifier): Make usage anayzer not recursively call collect_infects_from perf(es/minifier): Make analyzer not call collect_infects_from recursively Jan 26, 2025
Copy link

codspeed-hq bot commented Jan 27, 2025

CodSpeed Performance Report

Merging #9924 will degrade performances by 3.64%

Comparing kdy1:min-cache-infects (ec1460c) with main (6f781d8)

Summary

⚡ 3 improvements
❌ 2 regressions
✅ 191 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
es/full/minify/libraries/d3 806.7 ms 779.9 ms +3.44%
es/full/minify/libraries/moment 125.3 ms 129.2 ms -3.05%
es/full/minify/libraries/terser 634.2 ms 609.7 ms +4.03%
es/minifier/libs/lodash 216.9 ms 205.6 ms +5.47%
es/minifier/libs/moment 100.6 ms 104.4 ms -3.64%

kodiakhq[bot]
kodiakhq bot previously approved these changes Jan 28, 2025
@kdy1
Copy link
Member Author

kdy1 commented Jan 28, 2025

Diff:
image

@kdy1 kdy1 enabled auto-merge (squash) January 28, 2025 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants