Skip to content

Commit

Permalink
Merge pull request #1066 from glimmerjs/perf/remove-error-from-autotr…
Browse files Browse the repository at this point in the history
…acking-transaction

[PERF] Removes the Errors created for autotracking transactions
  • Loading branch information
Chris Garrett authored Mar 26, 2020
2 parents da47af0 + 8a15ba3 commit d16f573
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 @@ -25,7 +25,7 @@ class Tracker {
this.tags.add(tag);

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

this.last = tag;
Expand Down

0 comments on commit d16f573

Please sign in to comment.