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(transformer/arrow-function): store scope_id to avoid going through scopes #7041

Conversation

Dunqing
Copy link
Member

@Dunqing Dunqing commented Oct 31, 2024

Not sure if this will boost performance, so create a PR to see the benchmark

Copy link

graphite-app bot commented Oct 31, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “0-merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

@github-actions github-actions bot added A-transformer Area - Transformer / Transpiler C-performance Category - Solution not expected to change functional behavior, only performance labels Oct 31, 2024
Copy link
Member Author

Dunqing commented Oct 31, 2024

@Dunqing Dunqing force-pushed the 10-31-ci_transformer_enable_unfinished_plugins_in_benchmark branch from aae39c9 to 3aacc67 Compare October 31, 2024 15:58
@Dunqing Dunqing force-pushed the 10-31-perf_transformer_arrow-function_change_to_a_correct_scope_id_when_inserting_this branch from 21bc884 to 47e0e3a Compare October 31, 2024 15:58
Copy link

codspeed-hq bot commented Oct 31, 2024

CodSpeed Performance Report

Merging #7041 will not alter performance

Comparing 10-31-perf_transformer_arrow-function_change_to_a_correct_scope_id_when_inserting_this (d320f62) with main (9f611a1)

Summary

✅ 30 untouched benchmarks

@Dunqing Dunqing force-pushed the 10-31-perf_transformer_arrow-function_change_to_a_correct_scope_id_when_inserting_this branch 4 times, most recently from aa47e5d to 1674cf5 Compare November 1, 2024 06:49
@Dunqing Dunqing requested a review from overlookmotel November 1, 2024 09:46
@Dunqing Dunqing changed the title perf(transformer/arrow-function): change to a correct scope_id when inserting this perf(transformer/arrow-function): store scope_id to avoid going through scopes Nov 1, 2024
@overlookmotel
Copy link
Contributor

I've broken out the change to using AstBuilder::alloc_function_with_scope_id into a separate PR #7055. That change is good, but incidental to main thrust of this PR.

Copy link
Contributor

@overlookmotel overlookmotel left a comment

Choose a reason for hiding this comment

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

I'm not sure if this is a good idea or not. It makes entering/exiting functions more expensive, in order to make resolving this bindings cheaper.

ThisVar is 24 bytes, and it creates one for every function. Whereas previously SparseStack only took 1 byte (a bool) for each function (except for functions which need _this inserted into them, which take a further 24 bytes).

On the positive side, you avoid having to search up the tree to find the scope of the parent function when you do find a this within an arrow function. Note: That search only happens on 1st this within that parent function.

So whether this change is a perf improvement or not depends on which is more common: functions, or this within arrow functions (in particular, a single this). The answer will depend on the nature of the code being transformed.

On our benchmarks, it appears to be mostly negative (-0.1% to -0.3%) and it's hard to see if it's positive or negative on RadixUIAdoptionSection.jsx benchmark, as that one is so noisy. But either way, it doesn't make much difference.

If you want to merge this, I don't object. If you want to close it, I don't object either!

One last thing: If you do close it, please don't see it as wasted time. Often the only way to find out if something improves perf or not is to try, and often the result is unexpected - things you think will have marginal impact can surprisingly win you 5%, and other things you had high hopes for do nothing. So we need to experiment.

@Dunqing
Copy link
Member Author

Dunqing commented Nov 1, 2024

I'm not sure if this is a good idea or not. It makes entering/exiting functions more expensive, in order to make resolving this bindings cheaper.

ThisVar is 24 bytes, and it creates one for every function. Whereas previously SparseStack only took 1 byte (a bool) for each function (except for functions which need _this inserted into them, which take a further 24 bytes).

On the positive side, you avoid having to search up the tree to find the scope of the parent function when you do find a this within an arrow function. Note: That search only happens on 1st this within that parent function.

So whether this change is a perf improvement or not depends on which is more common: functions, or this within arrow functions (in particular, a single this). The answer will depend on the nature of the code being transformed.

On our benchmarks, it appears to be mostly negative (-0.1% to -0.3%) and it's hard to see if it's positive or negative on RadixUIAdoptionSection.jsx benchmark, as that one is so noisy. But either way, it doesn't make much difference.

If you want to merge this, I don't object. If you want to close it, I don't object either!

One last thing: If you do close it, please don't see it as wasted time. Often the only way to find out if something improves perf or not is to try, and often the result is unexpected - things you think will have marginal impact can surprisingly win you 5%, and other things you had high hopes for do nothing. So we need to experiment.

Thanks for taking your precious time on this! Yes, we can't determine which way now, I will leave it until I move the implementation of ArrowFunction to the common module, in that time we can use it in async-to-generator and async-generator-functions plugins where we may get more samples to verify which one is better.

@Dunqing Dunqing force-pushed the 10-31-ci_transformer_enable_unfinished_plugins_in_benchmark branch 2 times, most recently from d2b9343 to fe6818b Compare November 2, 2024 15:07
@Dunqing Dunqing changed the base branch from 10-31-ci_transformer_enable_unfinished_plugins_in_benchmark to graphite-base/7041 November 2, 2024 15:17
@Dunqing Dunqing force-pushed the 10-31-perf_transformer_arrow-function_change_to_a_correct_scope_id_when_inserting_this branch from 1674cf5 to ab06cc1 Compare November 3, 2024 16:07
@Dunqing Dunqing changed the base branch from graphite-base/7041 to main November 3, 2024 16:07
@Dunqing Dunqing force-pushed the 10-31-perf_transformer_arrow-function_change_to_a_correct_scope_id_when_inserting_this branch from ab06cc1 to d320f62 Compare November 3, 2024 16:08
@Dunqing
Copy link
Member Author

Dunqing commented Nov 6, 2024

Closing as we don't see a noticeable performance improvement

@Dunqing Dunqing closed this Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-transformer Area - Transformer / Transpiler C-performance Category - Solution not expected to change functional behavior, only performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants