Skip to content

Commit ac95732

Browse files
clydinangular-robot[bot]
authored andcommitted
perf(@angular-devkit/build-angular): minor sourcemap ignorelist improvements for esbuild builder
This provides a minor performance benefit for the generation of the Chrome sourcemap ignorelist generation. Memory is shared were possible and string searching is reduced in certain cases.
1 parent a9c6b44 commit ac95732

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

packages/angular_devkit/build_angular/src/builders/browser-esbuild/sourcemap-ignorelist-plugin.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ import type { Plugin } from 'esbuild';
1515
*/
1616
const IGNORE_LIST_ID = 'x_google_ignoreList';
1717

18+
/**
19+
* The UTF-8 bytes for the node modules check text used to avoid unnecessary parsing
20+
* of a full source map if not present in the source map data.
21+
*/
22+
const NODE_MODULE_BYTES = Buffer.from('node_modules/', 'utf-8');
23+
1824
/**
1925
* Minimal sourcemap object required to create the ignore list.
2026
*/
@@ -50,10 +56,15 @@ export function createSourcemapIngorelistPlugin(): Plugin {
5056
continue;
5157
}
5258

53-
const contents = Buffer.from(file.contents);
59+
// Create a Buffer object that shares the memory of the output file contents
60+
const contents = Buffer.from(
61+
file.contents.buffer,
62+
file.contents.byteOffset,
63+
file.contents.byteLength,
64+
);
5465

5566
// Avoid parsing sourcemaps that have no node modules references
56-
if (!contents.includes('node_modules/')) {
67+
if (!contents.includes(NODE_MODULE_BYTES)) {
5768
continue;
5869
}
5970

@@ -62,10 +73,8 @@ export function createSourcemapIngorelistPlugin(): Plugin {
6273

6374
// Check and store the index of each source originating from a node modules directory
6475
for (let index = 0; index < map.sources.length; ++index) {
65-
if (
66-
map.sources[index].startsWith('node_modules/') ||
67-
map.sources[index].includes('/node_modules/')
68-
) {
76+
const location = map.sources[index].indexOf('node_modules/');
77+
if (location === 0 || (location > 0 && map.sources[index][location - 1] === '/')) {
6978
ignoreList.push(index);
7079
}
7180
}

0 commit comments

Comments
 (0)