Skip to content

perf(turbopack): Mark more async fns without await as async #80642

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

Open
wants to merge 1 commit into
base: canary
Choose a base branch
from

Conversation

HerringtonDarkholme
Copy link
Contributor

@HerringtonDarkholme HerringtonDarkholme commented Jun 18, 2025

What?

Follow up of #80628, mark more task function as sync.

Why?

As stated in previous PR, using sync function can improve performance.

How?

I am using ast-grep codemod to find all functions without await expression or await in macro.
Then a cargo fmt is run to format code.

Click here to see rule definition, or see in playground link above
id: turbo-async-fn-without-await
message: 'Async function is denoted as `#[turbo_tasks::function]` but does not have `await`.'
severity: error
language: Rust
utils:
 await_like:
   any:
   - kind: await_expression
   # ast-grep cannot handle macro. use regex instead.
   - kind: macro_invocation
     regex: '\.await'
rule:
 kind: function_modifier
 regex: async 
 inside:
   pattern: 'async fn $NAME'
   kind: function_item
   follows:
     pattern: '#[turbo_tasks::function]'
   has:
     field: body
     not:
       has:
         matches: await_like
         stopBy: end

Follow up

A follow up PR to add the rule above and its test case into next.js can also be done if maintainers think it is valuable.

@ijjk ijjk added the Turbopack Related to Turbopack with Next.js. label Jun 18, 2025
@ijjk
Copy link
Member

ijjk commented Jun 18, 2025

Allow CI Workflow Run

  • approve CI run for commit: 60c12d7

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

Copy link

codspeed-hq bot commented Jun 18, 2025

CodSpeed Performance Report

Merging #80642 will improve performances by 20.16%

Comparing HerringtonDarkholme:perf-sync (60c12d7) with canary (0c454db)

Summary

⚡ 1 improvements
✅ 2 untouched benchmarks
⁉️ 9 dropped benchmarks

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

Benchmarks breakdown

Benchmark BASE HEAD Change
hmr_updates_small_5 20.5 µs 17 µs +20.16%
⁉️ build[date-fns-all] 2.8 s N/A N/A
⁉️ build[date-fns-single] 1.6 s N/A N/A
⁉️ build[framer-motion-all] 3.9 s N/A N/A
⁉️ build[framer-motion-single] 2.7 s N/A N/A
⁉️ build[joy] 2.5 s N/A N/A
⁉️ build[lucide-react-all] 12.5 s N/A N/A
⁉️ build[lucide-react-single] 1 s N/A N/A
⁉️ build[mui] 3.9 s N/A N/A
⁉️ build[shiki] 6.3 s N/A N/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Turbopack Related to Turbopack with Next.js.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants