Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

perf($compile): wrap try/catch of collect comment directives into a function to avoid V8 deopt #14848

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2052,26 +2052,32 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
addTextInterpolateDirective(directives, node.nodeValue);
break;
case NODE_TYPE_COMMENT: /* Comment */
try {
match = COMMENT_DIRECTIVE_REGEXP.exec(node.nodeValue);
if (match) {
nName = directiveNormalize(match[1]);
if (addDirective(directives, nName, 'M', maxPriority, ignoreDirective)) {
attrs[nName] = trim(match[2]);
}
}
} catch (e) {
// turns out that under some circumstances IE9 throws errors when one attempts to read
// comment's node value.
// Just ignore it and continue. (Can't seem to reproduce in test case.)
}
collectCommentDirectives(node, directives, attrs, maxPriority, ignoreDirective);
break;
}

directives.sort(byPriority);
return directives;
}

function collectCommentDirectives(node, directives, attrs, maxPriority, ignoreDirective) {
// function created because of performance, try/catch disables
// the optimization of the whole function #14848
try {
var match = COMMENT_DIRECTIVE_REGEXP.exec(node.nodeValue);
if (match) {
var nName = directiveNormalize(match[1]);
if (addDirective(directives, nName, 'M', maxPriority, ignoreDirective)) {
attrs[nName] = trim(match[2]);
}
}
} catch (e) {
// turns out that under some circumstances IE9 throws errors when one attempts to read
// comment's node value.
// Just ignore it and continue. (Can't seem to reproduce in test case.)
}
}

/**
* Given a node with an directive-start it collects all of the siblings until it finds
* directive-end.
Expand Down