Skip to content

Commit

Permalink
[PERF] Removes the Errors created for autotracking transactions
Browse files Browse the repository at this point in the history
These errors are expensive to generate, and have become problematic for
development mode in general. The plan is to remove them for now, and try
to bring them back some time in the future in a opt-in way that is more
conventional and comprehensive (e.g. show all possible consumption
locations, not just the first one).
  • Loading branch information
Chris Garrett committed Mar 25, 2020
1 parent 858de79 commit 8a15ba3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
18 changes: 4 additions & 14 deletions packages/@glimmer/validator/lib/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { DEBUG } from '@glimmer/env';

interface AutotrackingTransactionSourceData {
context?: string;
error: Error;
}

export let runInAutotrackingTransaction:
Expand All @@ -22,7 +21,7 @@ export let assertTagNotConsumed:
| undefined
| (<T>(tag: Tag, obj?: T, keyName?: keyof T | string | symbol, forceHardError?: boolean) => void);

export let markTagAsConsumed: undefined | ((_tag: Tag, sourceError: Error) => void);
export let markTagAsConsumed: undefined | ((_tag: Tag) => void);

if (DEBUG) {
let DEPRECATE_IN_AUTOTRACKING_TRANSACTION = false;
Expand Down Expand Up @@ -145,25 +144,16 @@ if (DEBUG) {
message.push(`\`${String(keyName)}\` was first used:\n\n${sourceData.context}`);
}

if (sourceData.error.stack) {
let sourceStack = sourceData.error.stack;
let thirdIndex = nthIndex(sourceStack, '\n', 3);
sourceStack = sourceStack.substr(thirdIndex);

message.push(`Stack trace for the first usage: ${sourceStack}`);
}

message.push(`Stack trace for the update:`);

return message.join('\n\n');
};

markTagAsConsumed = (_tag: Tag, sourceError: Error) => {
markTagAsConsumed = (_tag: Tag) => {
if (!AUTOTRACKING_TRANSACTION || AUTOTRACKING_TRANSACTION.has(_tag)) return;

AUTOTRACKING_TRANSACTION.set(_tag, {
context: debuggingContexts!.map(c => c.replace(/^/gm, ' ').replace(/^ /, '-')).join('\n\n'),
error: sourceError,
});

// We need to mark the tag and all of its subtags as consumed, so we need to
Expand All @@ -172,11 +162,11 @@ if (DEBUG) {
let tag = _tag as any;

if (tag.subtag) {
markTagAsConsumed!(tag.subtag, sourceError);
markTagAsConsumed!(tag.subtag);
}

if (tag.subtags) {
tag.subtags.forEach((tag: Tag) => markTagAsConsumed!(tag, sourceError));
tag.subtags.forEach((tag: Tag) => markTagAsConsumed!(tag));
}
};

Expand Down
2 changes: 1 addition & 1 deletion packages/@glimmer/validator/lib/tracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Tracker {
this.tags.add(tag);

if (DEBUG) {
markTagAsConsumed!(tag, new Error());
markTagAsConsumed!(tag);
}

this.last = tag;
Expand Down

0 comments on commit 8a15ba3

Please sign in to comment.