Skip to content

Comments

feat: mutate Output and OutputChunk#1082

Merged
hyf0 merged 5 commits intomainfrom
mutate-output-chunk
May 10, 2024
Merged

feat: mutate Output and OutputChunk#1082
hyf0 merged 5 commits intomainfrom
mutate-output-chunk

Conversation

@underfin
Copy link
Contributor

@underfin underfin commented May 10, 2024

Description

The pr intends to make the the item of Output is mutable.

First, it should be mutable at rust side and js side, i changed the bundle argument to Vec<Output> at Plugin#generate_bundle/write_bundle, before it using &Vec<Output>, it will let the hook can mutate bundle, so it need to return an new bundle, if you not changed it, just return the original value. It also remove Arc at Output, using Arc is difficult to mutate it.

For rust side data pass to js side, it need to serialize and deserialize, it has some overhead. Here is some way to do it at the binding side, here only discuss mutate the item of Output, not including delete item and add item.
A. serialize the Output to js side, and mutate it, then serialize it to rust side. It has some unnecessary overhead if we only mutate one field of dada.
B. serialize the Output to js side but hold on the Output mutable reference and export the setter function of fileds, if some fields mutate, it only need to serialize corresponding data to rust side.

The pr implement B, it is better than A. If you have some good ideas, please let me know.

I will support the delete the item of Output at next pr. It only need to export a deleteItem API and using Proxy to intercept it at js side.

For add item to Output, because the data comes from js side, we need to serialize it to rust side and push to Output. But it hasn't the situation at now, it will be delay util somebody need the feature.

@netlify
Copy link

netlify bot commented May 10, 2024

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit 5023268
🔍 Latest deploy log https://app.netlify.com/sites/rolldown-rs/deploys/663ddce704dd6a000840f812

@codecov
Copy link

codecov bot commented May 10, 2024

Codecov Report

Attention: Patch coverage is 83.33333% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 87.24%. Comparing base (8c55a62) to head (5023268).
Report is 23 commits behind head on main.

Files Patch % Lines
.../rolldown_plugin/src/plugin_driver/output_hooks.rs 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1082      +/-   ##
==========================================
- Coverage   87.25%   87.24%   -0.01%     
==========================================
  Files         116      116              
  Lines        5797     5795       -2     
==========================================
- Hits         5058     5056       -2     
  Misses        739      739              

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

@github-actions
Copy link
Contributor

github-actions bot commented May 10, 2024

Benchmarks Rust

group                                      pr                                     target
-----                                      --                                     ------
rolldown benchmark/threejs-bundle          1.00     29.1±0.44ms        ? ?/sec    1.00     29.1±0.31ms        ? ?/sec
rolldown benchmark/threejs-scan            1.01     20.6±1.30ms        ? ?/sec    1.00     20.4±0.30ms        ? ?/sec
rolldown benchmark/threejs-sourcemap       1.00     41.4±2.27ms        ? ?/sec    1.00     41.2±0.72ms        ? ?/sec
rolldown benchmark/threejs10x-bundle       1.01    310.0±3.51ms        ? ?/sec    1.00    307.5±1.90ms        ? ?/sec
rolldown benchmark/threejs10x-scan         1.00    204.3±6.10ms        ? ?/sec    1.01    207.0±4.95ms        ? ?/sec
rolldown benchmark/threejs10x-sourcemap    1.01   427.2±10.86ms        ? ?/sec    1.00    424.2±8.05ms        ? ?/sec

Benchmarks Rust

group                                      pr                                     target
-----                                      --                                     ------
rolldown benchmark/threejs-bundle          1.00     29.2±0.40ms        ? ?/sec    1.00     29.2±0.34ms        ? ?/sec
rolldown benchmark/threejs-scan            1.00     20.8±1.06ms        ? ?/sec    1.04     21.6±0.78ms        ? ?/sec
rolldown benchmark/threejs-sourcemap       1.00     40.6±0.99ms        ? ?/sec    1.02     41.6±0.93ms        ? ?/sec
rolldown benchmark/threejs10x-bundle       1.00    314.5±3.88ms        ? ?/sec    1.00    313.8±3.26ms        ? ?/sec
rolldown benchmark/threejs10x-scan         1.01    207.0±4.94ms        ? ?/sec    1.00    205.7±2.77ms        ? ?/sec
rolldown benchmark/threejs10x-sourcemap    1.00    426.5±6.13ms        ? ?/sec    1.00   426.7±11.22ms        ? ?/sec

@hyf0
Copy link
Member

hyf0 commented May 10, 2024

For add item to Output, because the data comes from js side, we need to serialize it to rust side and push to Output. But it hasn't the situation at now, it will be delay util somebody need the feature.

Be hesitate to support such behavior. Users should use this.emitFile to add item in output. https://rollupjs.org/plugin-development/#generatebundle:~:text=Do%20not%20directly%20add%20assets%20to%20the%20bundle.%20This%20circumvents%20internal%20mechanisms%20that%20Rollup%20has%20for%20tracking%20assets

@codspeed-hq
Copy link

codspeed-hq bot commented May 10, 2024

CodSpeed Performance Report

Merging #1082 will not alter performance

Comparing mutate-output-chunk (5023268) with main (bc1b3ac)

Summary

✅ 6 untouched benchmarks

@hyf0 hyf0 added this pull request to the merge queue May 10, 2024
Merged via the queue into main with commit 430d642 May 10, 2024
@hyf0 hyf0 deleted the mutate-output-chunk branch May 10, 2024 09:05
github-merge-queue bot pushed a commit that referenced this pull request Jun 25, 2025
…til needed (#5058)

These two lines clones the whole bundle output. This is because
`args.bundle` is `Vec<Output>` where `Output` is a enum that contains a
`Box`.

https://github.com/rolldown/rolldown/blob/35d8e1569d820347646a014fca28ed32457f912c/crates/rolldown_binding/src/options/plugin/js_plugin.rs#L483

https://github.com/rolldown/rolldown/blob/35d8e1569d820347646a014fca28ed32457f912c/crates/rolldown_binding/src/options/plugin/js_plugin.rs#L510

While this `.clone` is inevitable to allow referencing the `bundle`
parameter of `generateBundle` hook after the hook has end, the content
of `bundle` parameter does not need to have a separate value, because it
is readonly (the modification is done via `ChangedOutputs` instead).
This PR changes `Box` to `Arc` so that we can share the underlying
value.

This PR will have a bigger impact if the output is large. For example,
`astro build` with https://github.com/withastro/astro.build used ~8GB of
memory previously (if the GC does not run frequently enough). With this
PR, it now uses ~3GB.

refs #1082
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants