Skip to content
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

[api-minor] Add a temporary function-cache in AlternateCS.prototype.getRgbBuffer, and disable eval support by default #19428

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Snuffleupagus
Copy link
Collaborator

@Snuffleupagus Snuffleupagus commented Feb 6, 2025

  • Add a temporary function-cache in AlternateCS.prototype.getRgbBuffer

    This supplements, rather than replaces, the existing caching in PDFFunction.constructPostScript since that one still makes sense given that functions are cached on the page-level.
    Using an additional cache helps improve performance because:

    • There are many fewer function calls, and overall less parsing this way.

    • For the common case of Uint8Array-data we're able to use integer cache-keys, which is a lot faster than string concatenation.

    This significantly improves performance of the pr5134 test-case with isEvalSupported = false set, and testing locally in the viewer:

    • With the master branch and isEvalSupported = true, page 2 renders in approx. 340 milliseconds.

    • With the master branch and isEvalSupported = false, page 2 renders in approx. 1200 milliseconds.

    • With this patch and isEvalSupported = false, page 2 renders in approx. 380 milliseconds.

    While this is obviously still slower, the difference is now small enough that it shouldn't be too much of an issue in practice (compare with PR Use fuzzy-matching to improve cache hit rates with PostScriptEvaluator #18070) and the pr5134 test-case is an especially "bad" one w.r.t. its PostScript function use.

  • [api-minor] Disable eval support by default

    The idea behind this patch is to see if disabling of eval leads to any reports about bad performance, since the previous patch should have improved things a fair bit.

@Snuffleupagus Snuffleupagus force-pushed the AlternateCS-getRgbBuffer-tintCache branch from d36ce6c to 40d5b7c Compare February 6, 2025 11:31
@Snuffleupagus Snuffleupagus force-pushed the AlternateCS-getRgbBuffer-tintCache branch 3 times, most recently from 648e0af to 47c9a21 Compare February 21, 2025 10:38
@Snuffleupagus Snuffleupagus force-pushed the AlternateCS-getRgbBuffer-tintCache branch 3 times, most recently from 0eff81f to 996c17f Compare March 5, 2025 16:13
@Snuffleupagus Snuffleupagus force-pushed the AlternateCS-getRgbBuffer-tintCache branch from 996c17f to 91cd22b Compare March 10, 2025 20:26
@Snuffleupagus Snuffleupagus changed the title Add a temporary function-cache in AlternateCS.prototype.getRgbBuffer [api-minor] Add a temporary function-cache in AlternateCS.prototype.getRgbBuffer, and disable eval support by default Mar 11, 2025
@Snuffleupagus Snuffleupagus marked this pull request as ready for review March 11, 2025 09:11
@mozilla mozilla deleted a comment from moz-tools-bot Mar 11, 2025
@mozilla mozilla deleted a comment from moz-tools-bot Mar 11, 2025
@mozilla mozilla deleted a comment from moz-tools-bot Mar 11, 2025
@mozilla mozilla deleted a comment from moz-tools-bot Mar 11, 2025
@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.241.84.105:8877/d37b93ee73f9f2c/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.193.163.58:8877/78e6049b82cdea9/output.txt

@Snuffleupagus Snuffleupagus changed the title [api-minor] Add a temporary function-cache in AlternateCS.prototype.getRgbBuffer, and disable eval support by default [api-minor] Add a temporary function-cache in AlternateCS.prototype.getRgbBuffer, and disable eval support by default Mar 11, 2025
@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Failed

Full output at http://54.241.84.105:8877/d37b93ee73f9f2c/output.txt

Total script time: 30.69 mins

  • Unit tests: Passed
  • Integration Tests: FAILED
  • Regression tests: Passed

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/78e6049b82cdea9/output.txt

Total script time: 59.37 mins

  • Unit tests: Passed
  • Integration Tests: FAILED
  • Regression tests: FAILED
  different ref/snapshot: 1

Image differences available at: http://54.193.163.58:8877/78e6049b82cdea9/reftest-analyzer.html#web=eq.log

@Snuffleupagus Snuffleupagus force-pushed the AlternateCS-getRgbBuffer-tintCache branch from 91cd22b to 7611e64 Compare March 11, 2025 11:43
This supplements, rather than replaces, the existing caching in `PDFFunction.constructPostScript` since that one still makes sense given that functions are cached on the page-level.
Using an additional cache helps improve performance because:

 - There are many fewer function calls, and overall less parsing this way.

 - For the common case of `Uint8Array`-data we're able to use integer cache-keys, which is a lot faster than string concatenation.

This significantly improves performance of the `pr5134` test-case with `isEvalSupported = false` set, and testing locally in the viewer:

 - With the `master` branch and `isEvalSupported = true`, page 2 renders in approx. 340 milliseconds.

 - With the `master` branch and `isEvalSupported = false`, page 2 renders in approx. 1200 milliseconds.

 - With this patch and `isEvalSupported = false`, page 2 renders in approx. 380 milliseconds.

While this is obviously still slower, the difference is now small enough that it shouldn't be too much of an issue in practice (compare with PR 18070) and the `pr5134` test-case is an especially "bad" one w.r.t. its PostScript function use.
The idea behind this patch is to see if disabling of `eval` leads to any reports about bad performance, since the previous patch should have improved things a fair bit.
@Snuffleupagus Snuffleupagus force-pushed the AlternateCS-getRgbBuffer-tintCache branch from 7611e64 to 602824b Compare March 11, 2025 13:36
@Snuffleupagus Snuffleupagus marked this pull request as draft March 11, 2025 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants