From 3a40bd4e69c85c61be298684f1647768145389bc Mon Sep 17 00:00:00 2001 From: David Rodenas Pico Date: Thu, 30 Jun 2016 09:52:04 +0200 Subject: [PATCH 1/2] perf($compile): wrap try/catch of collect comment directives into a function to avoid V8 deopt --- src/ng/compile.js | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/ng/compile.js b/src/ng/compile.js index 68e49f2bcaf1..ab68485a09c9 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -2052,24 +2052,30 @@ 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(); break; } directives.sort(byPriority); return directives; + + function collectCommentDirectives() { + // function created because of performance, try/catch disables + // the optimization of the whole function #14848 + 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.) + } + } } /** From 686080189b1513ad1965464b9fec82cbf4775fa3 Mon Sep 17 00:00:00 2001 From: David Rodenas Pico Date: Thu, 30 Jun 2016 21:55:14 +0200 Subject: [PATCH 2/2] refactor($compile): move collectCommentDirectives outside collectDirectives because a possible performance concern --- src/ng/compile.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/ng/compile.js b/src/ng/compile.js index ab68485a09c9..9355630dca69 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -2052,29 +2052,29 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { addTextInterpolateDirective(directives, node.nodeValue); break; case NODE_TYPE_COMMENT: /* Comment */ - collectCommentDirectives(); + collectCommentDirectives(node, directives, attrs, maxPriority, ignoreDirective); break; } directives.sort(byPriority); return directives; + } - function collectCommentDirectives() { - // function created because of performance, try/catch disables - // the optimization of the whole function #14848 - 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]); - } + 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.) } + } 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.) } }