-
Notifications
You must be signed in to change notification settings - Fork 122
perf(externals-loading): merge multiple fetchBundle calls for the same URL #2307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3304a22
perf(externals-loading): merge multiple fetchBundle calls for the sam…
upupming 4c0ed3a
fix: async loader
upupming 19500a1
Merge branch 'main' into perf/merge-fetchbundle-calls
upupming 82e7124
Merge branch 'main' into perf/merge-fetchbundle-calls
upupming File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@lynx-js/externals-loading-webpack-plugin": patch | ||
| --- | ||
|
|
||
| perf: optimize external bundle loading by merging multiple `fetchBundle` calls for the same URL into a single request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...nals-loading-webpack-plugin/test/cases/externals-loading/merge-fetchBundle-calls/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { add } from 'foo'; | ||
| import { minus } from 'bar'; | ||
| import { mul } from 'baz/sub1'; | ||
| import { div } from 'baz/sub2'; | ||
| import { exp } from 'qux'; | ||
|
|
||
| console.info(add(1, 2)); | ||
| console.info(minus(1, 2)); | ||
| console.info(mul(2, 3)); | ||
| console.info(div(6, 2)); | ||
| console.info(exp(2, 3)); | ||
|
|
||
| it('should merge fetchBundle calls', async () => { | ||
| const fs = await import('node:fs'); | ||
| const path = await import('node:path'); | ||
|
|
||
| const background = fs.readFileSync( | ||
| path.resolve(__dirname, 'main:background.js'), | ||
| 'utf-8', | ||
| ); | ||
| const mainThread = fs.readFileSync( | ||
| path.resolve(__dirname, 'main:main-thread.js'), | ||
| 'utf-8', | ||
| ); | ||
|
|
||
| const backgroundFetchBundleCalls = background.split('fetchBundle' + '('); | ||
| const mainThreadFetchBundleCalls = mainThread.split('fetchBundle' + '('); | ||
| expect(backgroundFetchBundleCalls.length).toBe(2); | ||
| expect(mainThreadFetchBundleCalls.length).toBe(2); | ||
| }); |
80 changes: 80 additions & 0 deletions
80
...ding-webpack-plugin/test/cases/externals-loading/merge-fetchBundle-calls/rspack.config.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import { createConfig } from '../../../helpers/create-config.js'; | ||
|
|
||
| /** @type {import('@rspack/core').Configuration} */ | ||
| export default { | ||
| context: __dirname, | ||
| ...createConfig( | ||
| { | ||
| backgroundLayer: 'background', | ||
| mainThreadLayer: 'main-thread', | ||
| externals: { | ||
| 'foo': { | ||
| libraryName: 'Foo', | ||
| url: 'https://example.com/common.bundle', | ||
| async: false, | ||
| background: { | ||
| sectionPath: 'background', | ||
| }, | ||
| mainThread: { | ||
| sectionPath: 'mainThread', | ||
| }, | ||
| }, | ||
| 'bar': { | ||
| libraryName: 'Bar', | ||
| url: 'https://example.com/common.bundle', | ||
| async: false, | ||
| background: { | ||
| sectionPath: 'Bar__background', | ||
| }, | ||
| mainThread: { | ||
| sectionPath: 'Bar__mainThread', | ||
| }, | ||
| }, | ||
| 'baz/sub1': { | ||
| libraryName: ['Baz', 'Sub1'], | ||
| url: 'https://example.com/common.bundle', | ||
| async: false, | ||
| background: { | ||
| sectionPath: 'Baz__background', | ||
| }, | ||
| mainThread: { | ||
| sectionPath: 'Baz__mainThread', | ||
| }, | ||
| }, | ||
| 'baz/sub2': { | ||
| libraryName: ['Baz', 'Sub2'], | ||
| url: 'https://example.com/common.bundle', | ||
| async: false, | ||
| background: { | ||
| sectionPath: 'Baz__background', | ||
| }, | ||
| mainThread: { | ||
| sectionPath: 'Baz__mainThread', | ||
| }, | ||
| }, | ||
| 'baz/sub2?async': { | ||
| libraryName: ['Baz', 'Sub2'], | ||
| url: 'https://example.com/common.bundle', | ||
| async: true, | ||
| background: { | ||
| sectionPath: 'Baz__background', | ||
| }, | ||
| mainThread: { | ||
| sectionPath: 'Baz__mainThread', | ||
| }, | ||
| }, | ||
| 'qux': { | ||
| libraryName: 'Qux', | ||
| url: 'https://example.com/common.bundle', | ||
| async: true, | ||
| background: { | ||
| sectionPath: 'Qux__background', | ||
| }, | ||
| mainThread: { | ||
| sectionPath: 'Qux__mainThread', | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| ), | ||
| }; |
7 changes: 7 additions & 0 deletions
7
...ading-webpack-plugin/test/cases/externals-loading/merge-fetchBundle-calls/test.config.cjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| /** @type {import("@lynx-js/test-tools").TConfigCaseConfig} */ | ||
| module.exports = { | ||
| bundlePath: [ | ||
| 'main:main-thread.js', | ||
| 'main:background.js', | ||
| ], | ||
| }; |
6 changes: 6 additions & 0 deletions
6
...s/webpack/externals-loading-webpack-plugin/test/helpers/external-bundle-mock/bar/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // Copyright 2026 The Lynx Authors. All rights reserved. | ||
| // Licensed under the Apache License Version 2.0 that can be found in the | ||
| // LICENSE file in the root directory of this source tree. | ||
| export function minus(a, b) { | ||
| return a - b; | ||
| } |
4 changes: 4 additions & 0 deletions
4
...bpack/externals-loading-webpack-plugin/test/helpers/external-bundle-mock/bar/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "name": "bar", | ||
| "private": true | ||
| } |
7 changes: 7 additions & 0 deletions
7
.../webpack/externals-loading-webpack-plugin/test/helpers/external-bundle-mock/baz/common.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // Copyright 2026 The Lynx Authors. All rights reserved. | ||
| // Licensed under the Apache License Version 2.0 that can be found in the | ||
| // LICENSE file in the root directory of this source tree. | ||
|
|
||
| export function log(msg) { | ||
| console.info(msg); | ||
| } |
6 changes: 6 additions & 0 deletions
6
...s/webpack/externals-loading-webpack-plugin/test/helpers/external-bundle-mock/baz/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // Copyright 2026 The Lynx Authors. All rights reserved. | ||
| // Licensed under the Apache License Version 2.0 that can be found in the | ||
| // LICENSE file in the root directory of this source tree. | ||
|
|
||
| export * as Sub1 from './sub1/index.js'; | ||
| export * as Sub2 from './sub2/index.js'; |
4 changes: 4 additions & 0 deletions
4
...bpack/externals-loading-webpack-plugin/test/helpers/external-bundle-mock/baz/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "name": "baz", | ||
| "private": true | ||
| } |
9 changes: 9 additions & 0 deletions
9
...pack/externals-loading-webpack-plugin/test/helpers/external-bundle-mock/baz/sub1/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // Copyright 2026 The Lynx Authors. All rights reserved. | ||
| // Licensed under the Apache License Version 2.0 that can be found in the | ||
| // LICENSE file in the root directory of this source tree. | ||
| import { log } from '../common.js'; | ||
|
|
||
| export function mul(a, b) { | ||
| log(`mul(${a}, ${b})`); | ||
| return a * b; | ||
| } |
9 changes: 9 additions & 0 deletions
9
...pack/externals-loading-webpack-plugin/test/helpers/external-bundle-mock/baz/sub2/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // Copyright 2026 The Lynx Authors. All rights reserved. | ||
| // Licensed under the Apache License Version 2.0 that can be found in the | ||
| // LICENSE file in the root directory of this source tree. | ||
| import { log } from '../common.js'; | ||
|
|
||
| export function div(a, b) { | ||
| log(`div(${a}, ${b})`); | ||
| return a / b; | ||
| } |
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions
6
...s/webpack/externals-loading-webpack-plugin/test/helpers/external-bundle-mock/qux/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // Copyright 2026 The Lynx Authors. All rights reserved. | ||
| // Licensed under the Apache License Version 2.0 that can be found in the | ||
| // LICENSE file in the root directory of this source tree. | ||
| export function exp(a, b) { | ||
| return a ** b; | ||
| } |
4 changes: 4 additions & 0 deletions
4
...bpack/externals-loading-webpack-plugin/test/helpers/external-bundle-mock/qux/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "name": "qux", | ||
| "private": true | ||
| } |
16 changes: 10 additions & 6 deletions
16
packages/webpack/externals-loading-webpack-plugin/test/helpers/setup-env.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.