Skip to content

perf(wasm): sync init wasm in thread worker#2547

Merged
xusd320 merged 1 commit intonextfrom
perf/wasm-sync-thread
Jan 27, 2026
Merged

perf(wasm): sync init wasm in thread worker#2547
xusd320 merged 1 commit intonextfrom
perf/wasm-sync-thread

Conversation

@xusd320
Copy link
Contributor

@xusd320 xusd320 commented Jan 27, 2026

Fellow #2540
This pull request makes a minor update to how WebAssembly initialization is handled in the threadWorker.ts file. The change replaces the asynchronous initialization function with a synchronous one to better support worker thread spawning.

  • Replaced the default import initWasm with the synchronous initialization function initSync from utoo, and updated the assignment of wasm_bindgen accordingly in threadWorker.ts.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @xusd320, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on optimizing WebAssembly integration within worker threads by transitioning from an asynchronous to a synchronous initialization method. This change aims to enhance the reliability and performance of worker thread spawning. Accompanying this core modification are various dependency updates to ensure compatibility and leverage the latest versions of underlying libraries.

Highlights

  • WebAssembly Initialization: The WebAssembly initialization in threadWorker.ts has been switched from an asynchronous initWasm function to a synchronous initSync function to improve support for worker thread spawning.
  • Dependency Updates: Several dependencies in Cargo.lock have been updated, including downgrades for windows-sys and socket2, and updates to specific git commits for tokio and wasm_thread related crates.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@xusd320 xusd320 enabled auto-merge (squash) January 27, 2026 09:10
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the WebAssembly initialization in threadWorker.ts to use a synchronous function, initSync, which is crucial for supporting worker thread spawning as described. This change aligns with the stated goal of improving WASM performance in thread workers. The Cargo.lock file has been updated to reflect new dependency versions, including specific git references for tokio and wasm_thread forks, and some dependency downgrades.

Comment on lines +6282 to 6283
"windows-sys 0.52.0",
"windows-sys 0.59.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The stacker package now lists two different versions of windows-sys (0.52.0 and 0.59.0) as dependencies. This can lead to increased binary size and potential runtime conflicts due to multiple versions of the same crate being linked. It is best practice to consolidate to a single compatible version of a dependency across the project to avoid such issues. Please resolve this to use a single version of windows-sys for the stacker package.

 "windows-sys 0.59.0",

@github-actions
Copy link

📊 Performance Benchmark Report (with-antd)

🚀 Utoopack Performance Report: Async Task Scheduling Overhead Analysis

Report ID: utoopack_performance_report_20260127_091542
Generated: 2026-01-27 09:15:42
Trace File: trace_antd.json (1.5GB, 8.00M events)
Test Project: Unknown Project


📊 Executive Summary

This report analyzes the performance of Utoopack/Turbopack, covering the full spectrum of the Performance Analysis Protocol (P0-P4).

Key Findings

Metric Value Assessment
Total Wall Time 10,502.7 ms Baseline
Total Thread Work 90,536.4 ms ~8.6x parallelism
Thread Utilization 78.4% 🆗 Average
turbo_tasks::function Invocations 3,881,441 Total count
Meaningful Tasks (≥ 10µs) 1,545,434 (39.8% of total)
Tracing Noise (< 10µs) 2,336,007 (60.2% of total)

Workload Distribution by Tier

Category Tasks Total Time (ms) % of Work
P0: Runtime/Resolution 1,061,284 54,827.0 60.6%
P1: I/O & Heavy Tasks 38,071 3,714.1 4.1%
P3: Asset Pipeline 28,198 4,573.3 5.1%
P4: Bridge/Interop 0 0.0 0.0%
Other 417,881 20,127.2 22.2%

⚡ Parallelization Analysis (P0-P2)

Thread Utilization

Metric Value
Number of Threads 11
Total Thread Work 90,536.4 ms
Avg Work per Thread 8,230.6 ms
Theoretical Parallelism 8.62x
Thread Utilization 78.4%

Assessment: With 11 threads available, achieving 8.6x parallelism indicates reasonable throughput.


📈 Top 20 Tasks (Global)

These are the most significant tasks by total duration:

Total (ms) Count Avg (µs) % Work Task Name
45,718.2 879,618 52.0 50.5% turbo_tasks::function
8,730.2 124,002 70.4 9.6% task execution completed
6,470.6 83,912 77.1 7.1% turbo_tasks::resolve_call
3,073.1 33,126 92.8 3.4% analyze ecmascript module
2,183.3 67,043 32.6 2.4% precompute code generation
2,102.9 68,281 30.8 2.3% resolving
1,800.7 36,045 50.0 2.0% module
1,757.0 21,111 83.2 1.9% effects processing
1,533.4 11,632 131.8 1.7% process parse result
1,214.0 6,641 182.8 1.3% parse ecmascript
1,102.4 33,305 33.1 1.2% process module
1,039.3 36,120 28.8 1.1% internal resolving
846.7 29,109 29.1 0.9% resolve_relative_request
687.7 1,924 357.4 0.8% analyze variable values
501.1 21,353 23.5 0.6% handle_after_resolve_plugins
468.1 10,878 43.0 0.5% code generation
467.7 1,947 240.2 0.5% swc_parse
466.5 16,024 29.1 0.5% resolve_module_request
386.1 17,732 21.8 0.4% resolved
348.4 4,256 81.9 0.4% read file

🔍 Deep Dive by Tier

🔴 Tier 1: Runtime & Resolution (P0)

Focus: Task scheduling and dependency resolution.

Metric Value Status
Total Scheduling Time 54,827.0 ms ⚠️ High
Resolution Hotspots 9 tasks 🔍 Check Top Tasks

Potential P0 Issues:

  • Low thread utilization (78.4%) suggests critical path serialization or lock contention.
  • 2,336,007 tasks < 10µs (60.2%) contribute to scheduler pressure.

🟠 Tier 2: Physical & Resource Barriers (P1)

Focus: Hardware utilization, I/O, and heavy monoliths.

Metric Value Status
I/O Work (Estimated) 3,714.1 ms ✅ Healthy
Large Tasks (> 100ms) 16 🚨 Critical

Potential P1 Issues:

  • 16 tasks exceed 100ms. These "Heavy Monoliths" are prime candidates for splitting.

🟡 Tier 3: Architecture & Asset Pipeline (P2-P3)

Focus: Global state and transformation pipeline.

Metric Value Status
Asset Processing (P3) 4,573.3 ms 5.1% of work
Bridge Overhead (P4) 0.0 ms ✅ Low

💡 Recommendations (Prioritized P0-P2)

🚨 Critical: (P0) Improvement

Problem: 78.4% thread utilization.
Action:

  1. Profile lock contention if utilization < 60%.
  2. Convert sequential await chains to try_join.

⚠️ High Priority: (P1) Optimization

Problem: 16 heavy tasks detected.
Action:

  1. Identify module-level bottlenecks (e.g., barrel files).
  2. Optimize I/O batching for metadata.

⚠️ Medium Priority: (P3) Pipeline Efficiency

Action:

  1. Review transformation logic for frequently changed assets.
  2. Minimize cross-language serialization (P4) if overhead exceeds 10%.

📐 Diagnostic Signal Summary

Signal Status Finding
Tracing Noise (P0) ⚠️ Significant 60.2% of tasks < 10µs
Thread Utilization (P0) ✅ Good 78.4% utilization
Heavy Monoliths (P1) ⚠️ Detected 16 tasks > 100ms
Asset Pipeline (P3) 🔍 Review 4,573.3 ms total
Bridge/Interop (P4) ✅ Low 0.0 ms total

🎯 Action Items (Comprehensive P0-P4)

  1. [P0] Investigate task scheduling gaps for incremental gains
  2. [P1] Breakdown heavy monolith tasks (>100ms) to improve granularity
  3. [P1] Review I/O patterns for potential batching opportunities
  4. [P3] Optimize asset transformation pipeline hot-spots
  5. [P4] Reduce "chatty" bridge operations if interop overhead is significant

Report generated by Utoopack Performance Analysis Agent on 2026-01-27
Following: Utoopack Performance Analysis Agent Protocol

@xusd320 xusd320 disabled auto-merge January 27, 2026 09:33
@xusd320 xusd320 merged commit 2043e75 into next Jan 27, 2026
21 of 23 checks passed
@xusd320 xusd320 deleted the perf/wasm-sync-thread branch January 27, 2026 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants