Skip to content
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

Performance issue 47 #49

Merged
merged 6 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions lib/converter/collect-source-maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,6 @@

};

const saveSourceFile = async (filePath, data) => {
await Util.writeFile(filePath, JSON.stringify(data));

// save source and sourcemap file for debug
// https://evanw.github.io/source-map-visualization
// if (data.sourceMap) {
// await Util.writeFile(`${filePath}.js`, data.source);
// await Util.writeFile(`${filePath}.js.map`, JSON.stringify(data.sourceMap));
// }

};

const getInlineSourceMap = (content) => {
let smc;
try {
Expand All @@ -153,7 +141,8 @@

const collectSourceMaps = async (v8list, options) => {

const smList = [];
const sourceList = [];
const sourcemapList = [];
const concurrency = new Concurrency();
for (const item of v8list) {

Expand Down Expand Up @@ -192,11 +181,13 @@
const smc = getInlineSourceMap(source);
if (smc) {
sourceData.sourceMap = resolveSourceMap(smc.sourcemap, url);
smList.push({
sourcemapList.push({
url,
inline: true
});
await saveSourceFile(sourcePath, sourceData);
sourceList.push({
sourcePath, sourceData
});
continue;
}
// from url async
Expand All @@ -212,26 +203,38 @@
}

// no need check sourceMap
await saveSourceFile(sourcePath, sourceData);
sourceList.push({
sourcePath, sourceData
});

}

// from url concurrency
await concurrency.start(async (item) => {
const { sourceMapUrl, sourceData } = item;
const {
sourceMapUrl, sourcePath, sourceData
} = item;
const { url } = sourceData;
const data = await loadSourceMap(sourceMapUrl);
if (data) {
sourceData.sourceMap = resolveSourceMap(data, url);
smList.push({
sourcemapList.push({
url,
sourceMapUrl
});
}
await saveSourceFile(item.sourcePath, sourceData);

sourceList.push({
sourcePath,
sourceData
});

});

return smList;
return {

Check notice on line 234 in lib/converter/collect-source-maps.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/converter/collect-source-maps.js#L234

Unnecessary block.
sourceList,
sourcemapList
};

};

Expand Down
15 changes: 11 additions & 4 deletions lib/converter/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,7 @@ const convertV8List = (v8list, options) => {
delete item.ranges;
}
}
Util.logTime(`- parsed ast: ${sourcePath} (${EC.cyan(Util.BSF(maxContentLength))})`, time_start_ast);
Util.logTime(` ┌ [convert] parsed ast: ${sourcePath} (${EC.cyan(Util.BSF(maxContentLength))})`, time_start_ast);

// console.log(sourcePath, astInfo.statements.length);
// ============================
Expand All @@ -1549,7 +1549,9 @@ const convertV8List = (v8list, options) => {
locator,
maxContentLength,
decodedMappings: [],
cacheMap: new Map(),
rangeCache: new Map(),
diffCache: new Map(),
// cacheHits: 0,
// coverage info
bytes: [],
functions: [],
Expand All @@ -1566,7 +1568,7 @@ const convertV8List = (v8list, options) => {
const time_start_unpack = Date.now();
unpackDistFile(item, state, options);
const unpackedFiles = EC.cyan(`${state.originalList.length} files`);
Util.logTime(`- unpacked dist: ${sourcePath} (${unpackedFiles})`, time_start_unpack);
Util.logTime(` ┌ [convert] unpacked sourcemap: ${sourcePath} (${unpackedFiles})`, time_start_unpack);

stateList.push(state);

Expand All @@ -1575,7 +1577,12 @@ const convertV8List = (v8list, options) => {
const time_start_convert = Date.now();
const dataList = generateV8DataList(stateList, options);
const dataFiles = EC.cyan(`${dataList.v8DataList.length} files`);
Util.logTime(`- generated data list (${dataFiles})`, time_start_convert);

// stateList.forEach((st) => {
// console.log('diffCache', st.diffCache.size, 'cacheHits', st.cacheHits);
// });

Util.logTime(` ┌ [convert] converted data list (${dataFiles})`, time_start_convert);

return dataList;
};
Expand Down
47 changes: 35 additions & 12 deletions lib/converter/find-original-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,17 @@

// ========================================================================================================

const alignText = (gt, ot) => {
const alignText = (gt, ot, info) => {

const { diffCache } = info.state;

if (diffCache.has(gt)) {
const subMap = diffCache.get(gt);
if (subMap.has(ot)) {
// info.state.cacheHits += 1;
return subMap.get(ot);
}
}

const toList = (s) => {
return s.split('').map((v, i) => {
Expand Down Expand Up @@ -115,6 +125,15 @@
mergeList(gList, oList);
}

if (diffCache.has(gt)) {
const subMap = diffCache.get(gt);
subMap.set(ot, gl);
} else {
const subMap = new Map();
diffCache.set(gt, subMap);
subMap.set(ot, gl);
}

// console.log(gl);
return gl;
};
Expand All @@ -136,7 +155,11 @@
}
};

const getAlignPosition = (gt, gp, ot, direction) => {
const getAlignPosition = (info, direction) => {

Check warning on line 158 in lib/converter/find-original-range.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/converter/find-original-range.js#L158

A function should not mix return statements with and without a result.

const gt = info.generatedText;
const gp = info.generatedPos;
const ot = info.originalText;

// there is no need to align for long text
const maxLength = 500;
Expand All @@ -162,7 +185,7 @@
// only for original first line text

// exclusive
const list = alignText(gt, ot);
const list = alignText(gt, ot, info);
const item = list[gp];
if (item && item.original) {
return {
Expand Down Expand Up @@ -305,7 +328,7 @@

// =============================

return getAlignPosition(gt, gp, ot, direction);
return getAlignPosition(info, direction);

};

Expand All @@ -325,7 +348,7 @@
}

// no need comparison for fake source
if (info.fake) {
if (info.state.fake) {
return;
}

Expand Down Expand Up @@ -505,7 +528,7 @@
const direction = 'start';

const info = {
fake: state.fake,
state,
generatedText,
generatedPos,
originalText,
Expand Down Expand Up @@ -558,7 +581,7 @@
const direction = 'end';

const info = {
fake: state.fake,
state,
offset: end,
generatedText,
generatedPos,
Expand Down Expand Up @@ -826,11 +849,11 @@

const findOriginalRange = (start, end, state, originalMap) => {

const { sourcePath, cacheMap } = state;
const { sourcePath, rangeCache } = state;

const key = `${start}_${end}`;
if (cacheMap.has(key)) {
return cacheMap.get(key);
if (rangeCache.has(key)) {
return rangeCache.get(key);
}

const createMappingError = (errors) => {
Expand All @@ -843,7 +866,7 @@
};

// cache error response
cacheMap.set(key, res);
rangeCache.set(key, res);

return res;
};
Expand Down Expand Up @@ -884,7 +907,7 @@
};

// cache response
cacheMap.set(key, res);
rangeCache.set(key, res);

return res;

Expand Down
Loading