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

fix: detect a wider range of scheduled functions #1105

Merged
merged 6 commits into from Jun 9, 2022
Merged

Conversation

danez
Copy link
Contributor

@danez danez commented Jun 7, 2022

scheduled functions which are reassigned or not directly exported are now detected

This PR extends the functionality of the detection for the in-source-config of scheduled functions.

2 cases were not supported previously:

  1. The schedule is not directly supplied as string to the schedule() helper but assigned to a variable schedule(SCHEDULE, ...)
  2. The schedule helper is not directly exported (export const handler = schedule()) but instead assigned to a variable which is exported export { handler }

To solve both of these cases I opted to collect all variable bindings and their current value (only in the root scope). This is done by iterating through all nodes and collecting all declarations of variables and all reassigns. This method is memoized so that multiple calls (at the moment maximum 2) won't result in duplicated work.

Now, when the cron pattern in the schedule helper (1) or the export (2) is encountered as an identifier instead of the expected value, the code now can resolve the identifier to its value using the binding-map.

@danez danez added type: bug code to address defects in shipped code area: functions labels Jun 7, 2022
@danez danez requested a review from a team June 7, 2022 12:58
@github-actions
Copy link
Contributor

github-actions bot commented Jun 7, 2022

⏱ Benchmark results

Comparing with 123e7e8

largeDepsEsbuild: 7.4s

⬆️ 16.91% increase vs. 123e7e8

^                                                                   9.3s                                  
│                                                                   ┌──┐                                  
│   8.3s                                                            |  |                                  
│   ┌──┐            7.7s                                            |  |                    8.1s          
│   |  |            ┌──┐                                            |  |                    ┌──┐    7.4s  
│   |  |            |  |                                            |  |                    |  |    ┌──┐  
│ ──┼──┼────6.4s────┼──┼────6.3s────6.6s────────────6.7s────6.4s────┼──┼────6.5s────6.4s────┼──┼────|▒▒|──
│   |  |    ┌──┐    |  |    ┌──┐    ┌──┐    6.1s    ┌──┐    ┌──┐    |  |    ┌──┐    ┌──┐    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    ┌──┐    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-12    T-11    T-10    T-9     T-8     T-7     T-6     T-5     T-4     T-3     T-2     T-1      T    
Legend

largeDepsNft: 35s

^                                                                  44.6s                                  
│                                                                   ┌──┐                                  
│  39.9s           40.5s                                            |  |                                  
│   ┌──┐            ┌──┐                                            |  |                   37.5s          
│   |  |            |  |                                            |  |                    ┌──┐    35s   
│   |  |            |  |                                            |  |                    |  |    ┌──┐  
│ ──┼──┼────────────┼──┼───────────30.7s────────────32s────30.5s────┼──┼───30.2s────31s─────┼──┼────|▒▒|──
│   |  |    28s     |  |   29.1s    ┌──┐            ┌──┐    ┌──┐    |  |    ┌──┐    ┌──┐    |  |    |▒▒|  
│   |  |    ┌──┐    |  |    ┌──┐    |  |   27.6s    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    ┌──┐    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-12    T-11    T-10    T-9     T-8     T-7     T-6     T-5     T-4     T-3     T-2     T-1      T    
Legend

largeDepsZisi: 50.4s

^                                                                 1m 20.5s                                
│                                                                   ┌──┐                                  
│                                                                   |  |                   1m 11s         
│                                                                   |  |                    ┌──┐          
│                                                         1m 2.9s   |  |          1m 3.2s   |  |          
│                                                           ┌──┐    |  |  1m 2.2s   ┌──┐    |  |          
│  57.6s           58.3s                                    |  |    |  |    ┌──┐    |  |    |  |          
│ ──┌──┐────────────┌──┐────────────────────────────────────┼──┼────┼──┼────┼──┼────┼──┼────┼──┼───50.4s──
│   |  |            |  |            47s            48.3s    |  |    |  |    |  |    |  |    |  |    ┌──┐  
│   |  |   44.1s    |  |   45.1s    ┌──┐   43.6s    ┌──┐    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    ┌──┐    |  |    ┌──┐    |  |    ┌──┐    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-12    T-11    T-10    T-9     T-8     T-7     T-6     T-5     T-4     T-3     T-2     T-1      T    
Legend

@danez danez marked this pull request as draft June 7, 2022 13:01
scheduled functions which are reassigned or not directly exported are now detected
@danez danez marked this pull request as ready for review June 7, 2022 13:05
@danez danez requested a review from eduardoboucas June 8, 2022 16:56
Copy link
Member

@eduardoboucas eduardoboucas left a comment

Choose a reason for hiding this comment

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

Looks really good. I left some comments and questions, mostly related to the fact that traversing ASTs is tricky and we should go the extra mile to make sure stuff is easy to understand by our future selves!

src/runtimes/node/parser/exports.ts Outdated Show resolved Hide resolved
src/runtimes/node/parser/bindings.ts Outdated Show resolved Hide resolved
src/runtimes/node/parser/bindings.ts Outdated Show resolved Hide resolved
src/runtimes/node/parser/exports.ts Show resolved Hide resolved
src/runtimes/node/parser/exports.ts Show resolved Hide resolved
src/runtimes/node/parser/bindings.ts Outdated Show resolved Hide resolved
src/runtimes/node/parser/bindings.ts Show resolved Hide resolved
danez and others added 5 commits June 9, 2022 15:29
Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>
Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>
Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>
Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>
@danez danez requested a review from eduardoboucas June 9, 2022 14:24
Copy link
Member

@eduardoboucas eduardoboucas left a comment

Choose a reason for hiding this comment

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

🚀

src/runtimes/node/parser/exports.ts Show resolved Hide resolved
src/runtimes/node/parser/bindings.ts Show resolved Hide resolved
@danez danez added the automerge label Jun 9, 2022
@kodiakhq kodiakhq bot merged commit 32a7387 into main Jun 9, 2022
@kodiakhq kodiakhq bot deleted the schedule-functions branch June 9, 2022 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: functions automerge type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants