Skip to content

feat(turbopack): wasm file write support and available_parallelism for worker pool#138

Merged
xusd320 merged 1 commit into
utoofrom
feat/turbopack-node-wasm-improvements
Apr 7, 2026
Merged

feat(turbopack): wasm file write support and available_parallelism for worker pool#138
xusd320 merged 1 commit into
utoofrom
feat/turbopack-node-wasm-improvements

Conversation

@xusd320
Copy link
Copy Markdown

@xusd320 xusd320 commented Apr 7, 2026

Changes

turbo-tasks-fs

  • Add wasm32-specific file write/remove path via wasm_fs_offload client, gated behind #[cfg(all(target_family = "wasm", target_os = "unknown"))]
  • Fix symlink error message formatting

turbopack-node

  • Extract available_parallelism into a dedicated module for cross-platform concurrency detection
  • Simplify get_evaluate_pool to use available_parallelism() directly instead of available_parallelism().map_or(1, |v| v.get())
  • Clean up import formatting in evaluate.rs

Copy link
Copy Markdown

@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 introduces WASM-specific file system operations in turbo-tasks-fs and refactors turbopack-node to use a local available_parallelism module. A review comment identifies an improvement opportunity in the WASM file handling logic, suggesting a refactor to eliminate redundant matching and the use of unreachable!() to improve code clarity and safety.

Comment on lines +1185 to +1214
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
match &*self.content {
FileContent::Content(..) => {
let create_directory = compare == FileComparison::Create;
if create_directory && let Some(parent) = full_path.parent() {
self.inner.create_directory(parent).await.with_context(|| {
format!(
"failed to create directory {parent:?} for write to \
{full_path:?}",
)
})?;
}
let content = self.content.clone();
let FileContent::Content(file) = &*content else {
unreachable!()
};
wasm_fs_offload::CLIENT
.write(&full_path, file.content().to_bytes())
.instrument(tracing::info_span!("write file", name = ?full_path))
.await
.with_context(|| format!("failed to write to {full_path:?}"))?;
}
FileContent::NotFound => {
wasm_fs_offload::CLIENT
.remove_file(&full_path)
.instrument(tracing::info_span!("remove file", name = ?full_path))
.await
.with_context(|| format!("removing {full_path:?} failed"))?;
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The WASM-specific file operation block contains redundant logic and an unnecessary double-match pattern. By cloning the content Arc once before the match, you can bind the inner file value directly in the first match arm, avoiding the need for a second let...else with an unreachable!() check. This also ensures the content remains alive across the .await points in a cleaner way.

                #[cfg(all(target_family = "wasm", target_os = "unknown"))]
                {
                    let content = self.content.clone();
                    match &*content {
                        FileContent::Content(file) => {
                            let create_directory = compare == FileComparison::Create;
                            if create_directory && let Some(parent) = full_path.parent() {
                                self.inner.create_directory(parent).await.with_context(|| {
                                    format!(
                                        "failed to create directory {parent:?} for write to \
                                         {full_path:?}",
                                    )
                                })?;
                            }
                            wasm_fs_offload::CLIENT
                                .write(&full_path, file.content().to_bytes())
                                .instrument(tracing::info_span!("write file", name = ?full_path))
                                .await
                                .with_context(|| format!("failed to write to {full_path:?}"))?;
                        }
                        FileContent::NotFound => {
                            wasm_fs_offload::CLIENT
                                .remove_file(&full_path)
                                .instrument(tracing::info_span!("remove file", name = ?full_path))
                                .await
                                .with_context(|| format!("removing {full_path:?} failed"))?;
                        }
                    }
                }

…r worker pool

- turbo-tasks-fs: add wasm32-specific file write/remove via wasm_fs_offload
- turbopack-node: extract available_parallelism module for cross-platform concurrency
- turbopack-node: use available_parallelism() directly in evaluate pool setup
@xusd320 xusd320 force-pushed the feat/turbopack-node-wasm-improvements branch from 369e9b0 to aa2e21f Compare April 7, 2026 07:26
@xusd320 xusd320 merged this pull request into utoo Apr 7, 2026
3 of 6 checks passed
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.

1 participant