Skip to content

perf(transformer): speed up searching for position to insert new statements#6189

Closed
overlookmotel wants to merge 2 commits intomainfrom
09-30-perf_transformer_speed_up_searching_for_position_to_insert_new_statements
Closed

perf(transformer): speed up searching for position to insert new statements#6189
overlookmotel wants to merge 2 commits intomainfrom
09-30-perf_transformer_speed_up_searching_for_position_to_insert_new_statements

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Sep 30, 2024

To pass Babel's tests, we have to insert new statements after any existing import statements.

Currently we find the insert position by searching backwards from the end of the file for the last import statement. But for a large file, that's a lot of statements to search through. Instead, search from the start for the first statement which is not an import, and insert before it.

Pass one annoying Babel test case by also checking for case where file starts with a non-import statement, but then has import statements after it.

If the file is a script, can skip searching entirely, as only modules can contain import statements.

@graphite-app
Copy link
Contributor

graphite-app bot commented Sep 30, 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.

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 30, 2024

CodSpeed Performance Report

Merging #6189 will not alter performance

Comparing 09-30-perf_transformer_speed_up_searching_for_position_to_insert_new_statements (f028e3c) with main (a949ecb)

Summary

✅ 29 untouched benchmarks

@overlookmotel overlookmotel marked this pull request as draft September 30, 2024 20:58
@overlookmotel
Copy link
Member Author

Hard to see exactly with the noise in the benchmarks, but looks like this hurts perf, rather than improving it. I'll take another look.

@overlookmotel overlookmotel force-pushed the 09-30-perf_transformer_speed_up_searching_for_position_to_insert_new_statements branch from 925ae2d to 766da5b Compare September 30, 2024 21:06
@overlookmotel overlookmotel changed the base branch from 09-30-fix_transformer_fix_inserting_require_with_front_option to 09-30-refactor_transformer_insert_import_statement_or_require_depending_on_source_type September 30, 2024 21:06
@overlookmotel overlookmotel force-pushed the 09-30-perf_transformer_speed_up_searching_for_position_to_insert_new_statements branch from 766da5b to b310e7c Compare September 30, 2024 21:15
@overlookmotel overlookmotel changed the base branch from 09-30-refactor_transformer_insert_import_statement_or_require_depending_on_source_type to 09-30-perf_transformer_look_up_symbolid_for_require_only_once September 30, 2024 21:15
@overlookmotel overlookmotel force-pushed the 09-30-perf_transformer_look_up_symbolid_for_require_only_once branch from 8c05f2a to 825e3b8 Compare October 1, 2024 08:36
@overlookmotel overlookmotel force-pushed the 09-30-perf_transformer_speed_up_searching_for_position_to_insert_new_statements branch from b310e7c to 3c8b255 Compare October 1, 2024 08:36
@Boshen Boshen changed the base branch from 09-30-perf_transformer_look_up_symbolid_for_require_only_once to graphite-base/6189 October 1, 2024 08:41
@Boshen Boshen force-pushed the 09-30-perf_transformer_speed_up_searching_for_position_to_insert_new_statements branch from 3c8b255 to 8eb27ca Compare October 1, 2024 08:46
@Boshen Boshen force-pushed the graphite-base/6189 branch from 825e3b8 to da2b2a4 Compare October 1, 2024 08:46
@Boshen Boshen changed the base branch from graphite-base/6189 to main October 1, 2024 08:47
@Boshen Boshen force-pushed the 09-30-perf_transformer_speed_up_searching_for_position_to_insert_new_statements branch from 8eb27ca to 73df633 Compare October 1, 2024 08:47
@overlookmotel overlookmotel force-pushed the 09-30-perf_transformer_speed_up_searching_for_position_to_insert_new_statements branch from 73df633 to f028e3c Compare October 1, 2024 22:14
@overlookmotel
Copy link
Member Author

I give up. You'd think this would be better, but it appears it's not.

@overlookmotel overlookmotel deleted the 09-30-perf_transformer_speed_up_searching_for_position_to_insert_new_statements branch October 1, 2024 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-transformer Area - Transformer / Transpiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments