PHANTOM
🇮🇳 IN
Skip to content

Avoid unnecessary cloning of the code string#6262

Merged
lukastaegert merged 1 commit intomasterfrom
avoid-code-clone
Feb 6, 2026
Merged

Avoid unnecessary cloning of the code string#6262
lukastaegert merged 1 commit intomasterfrom
avoid-code-clone

Conversation

@lukastaegert
Copy link
Member

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

Description

A small thing I spotted, we first clone the code before parsing it, whch is not strictly necessary.

I noticed that we make a copy of all code before parsing, which is unnecessary.
Copilot AI review requested due to automatic review settings February 6, 2026 16:32
@vercel
Copy link

vercel bot commented Feb 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
rollup Ready Ready Preview, Comment Feb 6, 2026 4:33pm

Request Review

@github-actions
Copy link

github-actions bot commented Feb 6, 2026

Thank you for your contribution! ❤️

You can try out this pull request locally by installing Rollup via

npm install rollup/rollup#avoid-code-clone

Notice: Ensure you have installed the latest nightly Rust toolchain. If you haven't installed it yet, please see https://www.rust-lang.org/tools/install to learn how to download Rustup and install Rust.

or load it into the REPL:
https://rollup-jrj7qx700-rollup-js.vercel.app/repl/?pr=6262

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes memory usage in the NAPI bindings by avoiding an unnecessary string clone operation when parsing JavaScript/TypeScript code. The change replaces self.code.clone() with mem::take(&mut self.code) in the async parse task, which transfers ownership of the string instead of duplicating it. Additionally, the PR removes the unused swc_atoms dependency from the parse_ast crate.

Changes:

  • Replaced string cloning with mem::take in the NAPI async parse task to avoid duplicating potentially large code strings
  • Removed unused swc_atoms dependency from parse_ast crate

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

File Description
rust/bindings_napi/src/lib.rs Added std::mem import and replaced self.code.clone() with mem::take(&mut self.code) in ParseTask::compute to avoid string duplication
rust/parse_ast/Cargo.toml Removed unused swc_atoms dependency
rust/Cargo.lock Updated lockfile to reflect removal of swc_atoms dependency

@github-actions
Copy link

github-actions bot commented Feb 6, 2026

Performance report

  • BUILD: 7067ms, 820 MB
    • initialize: 0ms, 24.6 MB (+7%)
    • generate module graph: 2620ms, 633 MB
      • generate ast: 1388ms, 624 MB
    • sort and bind modules: 413ms, 691 MB
    • mark included statements: 4024ms, 820 MB
      • treeshaking pass 1: 2331ms (-126ms, -5.1%), 820 MB
      • treeshaking pass 2: 464ms, 844 MB
      • treeshaking pass 3: 395ms, 818 MB
      • treeshaking pass 4: 385ms, 850 MB
      • treeshaking pass 5: 381ms, 820 MB
  • GENERATE: 697ms, 928 MB (+2%)
    • initialize render: 0ms, 820 MB
    • generate chunks: 41ms, 844 MB
      • optimize chunks: 0ms, 836 MB
    • render chunks: 636ms, 901 MB (+2%)
    • transform chunks: 17ms, 928 MB (+2%)
    • generate bundle: 0ms, 928 MB (+2%)

@codecov
Copy link

codecov bot commented Feb 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.76%. Comparing base (f7e6a1b) to head (858369c).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6262   +/-   ##
=======================================
  Coverage   98.76%   98.76%           
=======================================
  Files         273      273           
  Lines       10714    10714           
  Branches     2855     2855           
=======================================
  Hits        10582    10582           
  Misses         89       89           
  Partials       43       43           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lukastaegert lukastaegert merged commit 74559c0 into master Feb 6, 2026
57 checks passed
@lukastaegert lukastaegert deleted the avoid-code-clone branch February 6, 2026 18:19
@github-actions
Copy link

This PR has been released as part of rollup@4.58.0. You can test it via npm install rollup.

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