-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize TextLayerBuilder_renderLayer() for text heavy documents. #5137
Optimize TextLayerBuilder_renderLayer() for text heavy documents. #5137
Conversation
/botio-linux preview |
From: Bot.io (Linux)ReceivedCommand cmd_preview from @timvandermeij received. Current queue size: 0 Live output at: http://107.21.233.14:8877/851e015707c435a/output.txt |
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/851e015707c435a/output.txt Total script time: 0.74 mins Published
|
var textScale = textDiv.dataset.canvasWidth / width; | ||
var rotation = textDiv.dataset.angle; | ||
var transform = 'scale(' + textScale + ', 1)'; | ||
transform = 'rotate(' + rotation + 'deg) ' + transform; | ||
if (rotation !== undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's keep it if (rotation) {
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
Could you also add |
This change improves the text layer creation of "normal" text heavy documents. It changes 2 things: * If the text element is not rotated, it will neither calculate nor apply a textTransform: rotate(0deg) to the text layer element. * For scaling the text layer div, the context will measure the width of the text in the given font. For many text documents the font changes seldom. If the font stays the same, the context does not need to be set to a new font especially avoiding the temporary creation of the same font string over and over again.
while at it i also changed the ascent calculation to a longer if/elseif block to enhance readability. |
Could you paste before/after profiler results? |
/botio-windows preview |
From: Bot.io (Windows)ReceivedCommand cmd_preview from @yurydelendik received. Current queue size: 0 Live output at: http://107.22.172.223:8877/41130516e7e3deb/output.txt |
From: Bot.io (Windows)SuccessFull output at http://107.22.172.223:8877/41130516e7e3deb/output.txt Total script time: 0.83 mins Published
|
@yurydelendik profiling was a bit of a challenge because admittedly it is not the most impacting part. I put custom profiling code into the affected methods. Their runtime goes down from 1901ms to 1735ms - about a 10% improve. Also the "overhead" of the text layer divs goes down by 10% from about 300 bytes to 270 bytes per div. |
maybe @nnethercote could tell me how he measures rss. so that I can give it a shot as well using his metric. i expect it to go down as well (maybe also 10% :-)) |
I have two scripts. The first is called
The second is called
If you run |
ah cool, i was hoping for a more high tec solution, but will give it a shot :) |
using @nnethercote script, i saw a peak rss of 679.90 MiB pre-patch and after the patch 653.89 MiB for the mentioned pdf. roughly 5% less. |
var width = ctx.measureText(textDiv.textContent).width; | ||
if (width > 0) { | ||
textLayerFrag.appendChild(textDiv); | ||
// Dataset values come of type string. | ||
var textScale = textDiv.dataset.canvasWidth / width; | ||
var rotation = textDiv.dataset.angle; | ||
var transform = 'scale(' + textScale + ', 1)'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't we use 'scaleX(' + textScale + ')'
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe, but that would be a different change. If desired we can sneak it in. but i do not want to delay the change by piggybacking other stuff.
I would assume that performance wise the functions are equivalent.
BTW, the measurements can be noisy. I usually run my before and after measurements 3 times to see how much variation there is. |
…rLayer Optimize TextLayerBuilder_renderLayer() for text heavy documents.
Looks good, thank you for the patch. |
This change improves the text layer creation of "normal" text heavy documents.
It changes 2 things:
textTransform: rotate(0deg) to the text layer element.
text in the given font. For many text documents the font changes seldom.
If the font stays the same, the context does not need to be set to a new font
especially avoiding the temporary creation of the same font string over and
over again.
The PDF from #4873 suits well as an example. I added counts for where rotation is zero, and the font is the the same. Rotation of all text elements (many thousands) is zero, and the font is often for hundreds of elements the same.