Skip to content

Commit

Permalink
fix: do not use affected for side-effects-flag-plugin (#7865)
Browse files Browse the repository at this point in the history
fix: do not use cacheUnaffected for side-effects-flag-plugin
  • Loading branch information
JSerFeng committed Sep 12, 2024
1 parent f6f1798 commit ef82144
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -656,23 +656,13 @@ async fn nmf_module(

#[plugin_hook(CompilationOptimizeDependencies for SideEffectsFlagPlugin)]
fn optimize_dependencies(&self, compilation: &mut Compilation) -> Result<Option<bool>> {
let mut modules: IdentifierSet = if compilation.options.new_incremental_enabled() {
compilation
.unaffected_modules_cache
.get_affected_modules_with_module_graph()
.lock()
.expect("should lock")
.iter()
.copied()
.collect()
} else {
compilation
.get_module_graph()
.modules()
.keys()
.copied()
.collect()
};
// TODO: use affected module optimization
let mut modules: IdentifierSet = compilation
.get_module_graph()
.modules()
.keys()
.copied()
.collect();
let mut new_connections = Default::default();
for module in modules.clone() {
optimize_incoming_connections(module, &mut modules, &mut new_connections, compilation);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Case re-export-optimization-for-inaffected-module: Step 0

## Changed Files


## Asset Files
- Bundle: bundle.js

## Manifest


## Update
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Case re-export-optimization-for-inaffected-module: Step 1

## Changed Files
- module.js

## Asset Files
- Bundle: bundle.js
- Manifest: main.LAST_HASH.hot-update.json, size: 28
- Update: main.LAST_HASH.hot-update.js, size: 616

## Manifest

### main.LAST_HASH.hot-update.json

```json
{"c":["main"],"r":[],"m":[]}
```


## Update


### main.LAST_HASH.hot-update.js

#### Changed Modules
- ./module.js

#### Changed Runtime Modules
- webpack/runtime/get_full_hash

#### Changed Content
```js
"use strict";
self["webpackHotUpdate"]('main', {
"./module.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
value: function() { return value; }
});
/* harmony import */var _reexports__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./reexports */ "./foo.js");

const value = '' + _reexports__WEBPACK_IMPORTED_MODULE_0__.v;


}),

},function(__webpack_require__) {
// webpack/runtime/get_full_hash
(() => {
__webpack_require__.h = function () {
return "CURRENT_HASH";
};

})();

}
);
```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const v = 'foo'
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {value} from "./module";

let v = value;
module.hot.accept('./module', () => {
v = value
});

it("should auto-reexport an ES6 imported value on accept with newTreeshaking", async function (done) {
expect(v).toBe("foo");
NEXT(
require("../../update")(done, true, () => {
expect(v).toBe("foo");
done();
})
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {v} from './reexports'
//
export const value = '' + v;
---
import {v} from './reexports'
export const value = '' + v;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import {v} from './foo';
export {v};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { v } from "./reexports-deep";
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** @type {import("@rspack/core").Configuration} */
module.exports = {
optimization: {
sideEffects: true,
providedExports: true,
},
experiments: {
rspackFuture: {
newIncremental: true
}
}
};

2 comments on commit ef82144

@rspack-bot
Copy link

Choose a reason for hiding this comment

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

📝 Benchmark detail: Open

Name Base (2024-09-12 b1bf153) Current Change
10000_development-mode + exec 2.25 s ± 51 ms 2.24 s ± 16 ms -0.31 %
10000_development-mode_hmr + exec 724 ms ± 4.9 ms 734 ms ± 15 ms +1.34 %
10000_production-mode + exec 2.84 s ± 49 ms 2.85 s ± 28 ms +0.63 %
arco-pro_development-mode + exec 1.84 s ± 71 ms 1.83 s ± 77 ms -0.52 %
arco-pro_development-mode_hmr + exec 434 ms ± 1.5 ms 435 ms ± 2.9 ms +0.22 %
arco-pro_production-mode + exec 3.24 s ± 86 ms 3.26 s ± 70 ms +0.73 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.31 s ± 72 ms 3.34 s ± 65 ms +0.94 %
threejs_development-mode_10x + exec 1.68 s ± 11 ms 1.68 s ± 17 ms -0.20 %
threejs_development-mode_10x_hmr + exec 807 ms ± 15 ms 804 ms ± 5.5 ms -0.36 %
threejs_production-mode_10x + exec 5.14 s ± 42 ms 5.19 s ± 29 ms +0.84 %

@rspack-bot
Copy link

Choose a reason for hiding this comment

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

📝 Ran ecosystem CI: Open

suite result
modernjs ✅ success
_selftest ✅ success
nx ❌ failure
rspress ✅ success
rslib ❌ failure
rsbuild ❌ failure
examples ✅ success

Please sign in to comment.