Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

Commit

Permalink
perf: do not load disabled source files
Browse files Browse the repository at this point in the history
  • Loading branch information
lachrist committed Feb 22, 2023
1 parent b051d68 commit 5d488c2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion components/agent/default/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const instrument = (
const source = createSource(url, content);
const mapping = loadSourceMap(source, map);
if (configuration["postmortem-function-exclusion"] !== true) {
fillSourceMap(mapping);
fillSourceMap(mapping, configuration);
}
const { messages, content: instrumented_content } = instrumentFrontend(
frontend,
Expand Down
29 changes: 16 additions & 13 deletions components/agent/default/source-map.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,28 @@ import {
isSourceEmpty,
getSourceUrl,
} from "../../source/index.mjs";
import { getConfigurationPackage } from "../../configuration-accessor/index.mjs";
import { readFile } from "../../file/index.mjs";
import { logDebug } from "../../log/index.mjs";

export const fillSourceMap = (mapping) => {
export const fillSourceMap = (mapping, configuration) => {
for (const url of getMappingSourceArray(mapping)
.filter(isSourceEmpty)
.map(getSourceUrl)) {
let content = null;
try {
// TODO
// Lookup the url in `configuration.packages` to see whether the url is
// enabled. If it is disabled, we can improve performance by not trying
// to load the source file.
content = readFile(url);
} catch (error) {
logDebug("could not load source file %j >> %O", url, error);
}
if (content !== null) {
updateMappingSource(mapping, createSource(url, content));
if (getConfigurationPackage(configuration, url).enabled) {
let content = null;
try {
// TODO
// Lookup the url in `configuration.packages` to see whether the url is
// enabled. If it is disabled, we can improve performance by not trying
// to load the source file.
content = readFile(url);
} catch (error) {
logDebug("could not load source file %j >> %O", url, error);
}
if (content !== null) {
updateMappingSource(mapping, createSource(url, content));
}
}
}
};
Expand Down
15 changes: 13 additions & 2 deletions components/agent/default/source-map.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { Buffer } from "node:buffer";
import { assertEqual, assertDeepEqual } from "../../__fixture__.mjs";
import { getUuid } from "../../uuid/random/index.mjs";
import { createSource, makeSourceLocation } from "../../source/index.mjs";
import {
extendConfiguration,
createConfiguration,
} from "../../configuration/index.mjs";
import { getTmpUrl } from "../../path/index.mjs";
import { toAbsoluteUrl } from "../../url/index.mjs";
import {
Expand All @@ -27,11 +31,18 @@ const empty_source_map = {
};

{
const configuration = extendConfiguration(
createConfiguration(getTmpUrl()),
{
"default-package": { enabled: true },
},
getTmpUrl(),
);
const url = toAbsoluteUrl(getUuid(), getTmpUrl());
const mapping = createMirrorMapping(createSource(url, null));
fillSourceMap(mapping);
fillSourceMap(mapping, configuration);
await writeFileAsync(new URL(url), "123;", "utf8");
fillSourceMap(mapping);
fillSourceMap(mapping, configuration);
assertDeepEqual(getMappingSourceArray(mapping), [createSource(url, "123;")]);
}

Expand Down

0 comments on commit 5d488c2

Please sign in to comment.