From 95f90755658de62f63eb2db00a32c1810fce1ada Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sun, 30 Dec 2018 14:34:43 +0100 Subject: [PATCH 1/2] Optimize `TextLayerRenderTask._layoutText` to avoid intermediate string creation This method creates quite a few intermediate strings on each call and it's called often, even for smaller documents like the Tracemonkey document. Scrolling from top to bottom in that document resulted in 12936 strings being created in this method. With this commit applied, this is reduced to 3610 strings. --- src/display/text_layer.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/display/text_layer.js b/src/display/text_layer.js index 6abd23e42..1ab9518e0 100644 --- a/src/display/text_layer.js +++ b/src/display/text_layer.js @@ -540,12 +540,12 @@ var renderTextLayer = (function renderTextLayerClosure() { let transform = ''; if (textDivProperties.canvasWidth !== 0 && width > 0) { textDivProperties.scale = textDivProperties.canvasWidth / width; - transform = 'scaleX(' + textDivProperties.scale + ')'; + transform = `scaleX(${textDivProperties.scale})`; } if (textDivProperties.angle !== 0) { - transform = 'rotate(' + textDivProperties.angle + 'deg) ' + transform; + transform = `rotate(${textDivProperties.angle}deg) ${transform}`; } - if (transform !== '') { + if (transform.length > 0) { textDivProperties.originalTransform = transform; textDiv.style.transform = transform; } From 5b57e69da256a9bdd2337d37188b8ba7cda7e24f Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sun, 30 Dec 2018 14:57:45 +0100 Subject: [PATCH 2/2] Optimize `CanvasGraphics.setFont` to avoid intermediate string creation This method creates quite a few intermediate strings on each call and it's called often, even for smaller documents like the Tracemonkey document. Scrolling from top to bottom in that document resulted in 14126 strings being created in this method. With this commit applied, this is reduced to 2018 strings. --- src/display/canvas.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/display/canvas.js b/src/display/canvas.js index 99c97e13f..4aadb70a3 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -1317,7 +1317,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { var name = fontObj.loadedName || 'sans-serif'; var bold = fontObj.black ? '900' : (fontObj.bold ? 'bold' : 'normal'); var italic = fontObj.italic ? 'italic' : 'normal'; - var typeface = '"' + name + '", ' + fontObj.fallbackName; + var typeface = `"${name}", ${fontObj.fallbackName}`; // Some font backends cannot handle fonts below certain size. // Keeping the font at minimal size and using the fontSizeScale to change @@ -1327,8 +1327,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size; this.current.fontSizeScale = size / browserFontSize; - var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface; - this.ctx.font = rule; + this.ctx.font = `${italic} ${bold} ${browserFontSize}px ${typeface}`; }, setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) { this.current.textRenderingMode = mode;