Skip to content

Commit

Permalink
Enable auto split for depCache
Browse files Browse the repository at this point in the history
  • Loading branch information
d3xter666 committed Nov 17, 2023
1 parent 3df4cef commit 0ecfd7d
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions lib/lbt/bundle/AutoSplitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ class AutoSplitter {
const numberOfParts = options.numberOfParts;
let totalSize = 0;
const moduleSizes = Object.create(null);
const depCacheSymbol = Symbol("depCache");
const depCacheSizes = [];
let depCacheLoaderSize = 0;
let depCacheSet = new Set();
this.optimize = !!options.optimize;

// ---- resolve module definition
Expand Down Expand Up @@ -76,8 +78,8 @@ class AutoSplitter {
});
break;
case SectionType.DepCache:
moduleSizes[depCacheSymbol] = "sap.ui.loader.config({depCacheUI5:{}});".length;
totalSize += moduleSizes[depCacheSymbol];
depCacheLoaderSize = "sap.ui.loader.config({depCacheUI5:{}});".length;
totalSize += depCacheLoaderSize;

section.modules.forEach( (module) => {
promises.push((async () => {
Expand All @@ -89,8 +91,12 @@ class AutoSplitter {
);
if (deps.length > 0) {
const depSize = `"${module}": [${deps.map((dep) => `"${dep}"`).join(",")}],`.length;
moduleSizes[depCacheSymbol] += depSize;
totalSize += depSize;

depCacheSizes.push({
size: depSize,
filters: [module, ...deps]
});
}
})());
});
Expand Down Expand Up @@ -204,10 +210,34 @@ class AutoSplitter {
case SectionType.DepCache:
currentSection = {
mode: SectionType.DepCache,
filters: section.modules.slice()
filters: []
};
currentModule.sections.push( currentSection );
totalSize += moduleSizes[depCacheSymbol];
totalSize += depCacheLoaderSize;

depCacheSizes.forEach((depCache) => {
if ( part + 1 < numberOfParts && totalSize + depCache.size / 2 > partSize ) {
currentSection.filters = Array.from(depCacheSet);
depCacheSet = new Set();
part++;
// start a new module
totalSize = depCacheLoaderSize;
currentSection = {
mode: SectionType.DepCache,
filters: []
};
currentModule = {
name: moduleNameWithPart.replace(/__part__/, part),
sections: [currentSection]
};
splittedModules.push(currentModule);
}

depCache.filters.forEach((moduleName) => depCacheSet.add(moduleName));
totalSize += depCache.size;
});

currentSection.filters = Array.from(depCacheSet);
break;
default:
break;
Expand Down

0 comments on commit 0ecfd7d

Please sign in to comment.