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

Commit

Permalink
perf: shorthand for begin/end group event pair
Browse files Browse the repository at this point in the history
Group-related messages compose a large part of the trace. Which is a 
problem because they carry a lot of useless information and they are 
ultimately removed from the final appmap event list. To solve this 
issue, I created a shorter representation in the frontend which is 
inflated in the backend.

[skip ci]
  • Loading branch information
lachrist committed Sep 13, 2022
1 parent 12729f3 commit cf04077
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 14 deletions.
17 changes: 17 additions & 0 deletions build/schema/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,22 @@
- before
- after

# Shorthand for group event pair to improve performance.
# Group-related messages are a large part of the trace.
- $id: group-message
type: object
additionalProperties: false
required: [type, group, child, description]
properties:
type:
const: group
group:
$ref: group
child:
$ref: group
description:
type: string

- $id: event-message
type: object
additionalProperties: false
Expand Down Expand Up @@ -1147,6 +1163,7 @@
- $ref: stop-message
- $ref: error-message
- $ref: source-message
- $ref: group-message
- $ref: event-message
- $ref: amend-message

Expand Down
7 changes: 7 additions & 0 deletions components/agent/default/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default (dependencies) => {
formatError,
formatStartTrack,
formatStopTrack,
formatGroup,
formatBeginEvent,
formatEndEvent,
formatBeforeEvent,
Expand Down Expand Up @@ -95,6 +96,12 @@ export default (dependencies) => {
requestRemoteAgentAsync: ({ emitter }, method, path, body) =>
requestRemoteEmitterAsync(emitter, method, path, body),
/* c8 ignore stop */
recordGroup: ({ emitter, frontend }, child, description) => {
sendEmitter(
emitter,
formatGroup(frontend, getCurrentGroup(), child, description),
);
},
recordBeginAmend: generateRecord(formatBeginAmend),
recordEndAmend: generateRecord(formatEndAmend),
recordBeforeAmend: generateRecord(formatBeforeAmend),
Expand Down
8 changes: 8 additions & 0 deletions components/agent/default/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const {
getInstrumentationIdentifier,
getSerializationEmptyValue,
getFreshTab,
recordGroup,
recordBeforeEvent,
recordAfterEvent,
formatQueryPayload,
Expand All @@ -40,6 +41,7 @@ getSerializationEmptyValue(agent);

assertEqual(typeof getInstrumentationIdentifier(agent), "string");
recordStartTrack(agent, "record", {}, null);
recordGroup(agent, 123, "description");
assertEqual(
evalGlobal(
instrument(agent, { url: "file:///base/main.js", content: "123;" }),
Expand All @@ -62,6 +64,12 @@ assertDeepEqual(takeLocalAgentTrace(agent, "record"), [
configuration: {},
url: null,
},
{
type: "group",
group: 0,
child: 123,
description: "description",
},
{
type: "source",
url: "file:///base/main.js",
Expand Down
6 changes: 6 additions & 0 deletions components/frontend/default/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ export default (dependencies) => {
message,
stack,
}),
formatGroup: ({}, group, child, description) => ({
type: "group",
group,
child,
description,
}),
formatBeginEvent: generateFormatEvent("begin"),
formatEndEvent: generateFormatEvent("end"),
formatBeforeEvent: generateFormatEvent("before"),
Expand Down
3 changes: 3 additions & 0 deletions components/frontend/default/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const {
instrument,
getFreshTab,
getBundlePayload,
formatGroup,
formatBeginEvent,
formatBeginAmend,
} = Frontend(dependencies);
Expand All @@ -45,6 +46,8 @@ assertEqual(typeof getSerializationEmptyValue(frontend), "symbol");

assertEqual(typeof getFreshTab(frontend), "number");

validateMessage(formatGroup(frontend, 123, 456, "description"));

validateMessage(formatStartTrack(frontend, "track", {}, null));

validateMessage(formatStopTrack(frontend, "track", 0));
Expand Down
16 changes: 2 additions & 14 deletions components/hook-group/node/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ const { Set } = globalThis;
export default (dependencies) => {
const {
util: { assert },
agent: {
getFreshTab,
recordBeginEvent,
recordEndEvent,
formatGroupPayload,
formatUngroupPayload,
},
agent: { recordGroup },
} = dependencies;
return {
hook: (agent, { ordering }) => {
Expand All @@ -23,13 +17,7 @@ export default (dependencies) => {
init: (id, description, _origin) => {
assert(!groups.has(id), "duplicate async id");
groups.add(id);
const tab = getFreshTab(agent);
recordBeginEvent(
agent,
tab,
formatGroupPayload(agent, id, description),
);
recordEndEvent(agent, tab, formatUngroupPayload(agent, id));
recordGroup(agent, id, description);
},
});
hook.enable();
Expand Down
26 changes: 26 additions & 0 deletions components/trace/appmap/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,32 @@ export default (dependencies) => {
errors.push(message);
} else if (type === "event") {
events.push(message);
} else if (type === "group") {
events.push(
{
type: "event",
site: "begin",
tab: 0,
group: message.group,
time: 0,
payload: {
type: "group",
group: message.child,
description: message.description,
},
},
{
type: "event",
site: "end",
tab: 0,
group: message.group,
time: 0,
payload: {
type: "ungroup",
group: message.child,
},
},
);
} else if (type === "source") {
sources.push(message);
} else if (type === "amend") {
Expand Down
6 changes: 6 additions & 0 deletions components/trace/appmap/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ assertDeepEqual(
arguments: [{ type: "string", print: "ARG-PRINT" }],
},
},
{
type: "group",
group: 0,
child: 1,
description: "description",
},
{
type: "event",
site: "end",
Expand Down

0 comments on commit cf04077

Please sign in to comment.