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

Simplify singularValueDecompose2dScale in order to make it using less memory #19721

Merged

Conversation

calixteman
Copy link
Contributor

In using the Firefox profiler (with JS allocations tracking) and wuppertal.pdf, I noticed we were using a bit too much memory for a function which is supposed to just compute 2 numbers. The memory used by itself isn't so important but having a too much objects lead to waste some time to gc them.

So this patch aims to simplify it a bit.

@calixteman
Copy link
Contributor Author

/botio test

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

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

Live output at: http://54.241.84.105:8877/6c0e683d8e5a4a6/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Failed

Full output at http://54.241.84.105:8877/6c0e683d8e5a4a6/output.txt

Total script time: 30.55 mins

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

Image differences available at: http://54.241.84.105:8877/6c0e683d8e5a4a6/reftest-analyzer.html#web=eq.log

@calixteman calixteman force-pushed the simplif_singular_decomposition branch from 011c05f to 73a62ee Compare March 25, 2025 16:58
@calixteman
Copy link
Contributor Author

/botio test

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

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

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

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Received

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

Live output at: http://54.193.163.58:8877/dbd0ded44b09b27/output.txt

@calixteman calixteman force-pushed the simplif_singular_decomposition branch from 73a62ee to 87b8ba5 Compare March 25, 2025 17:31
@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Failed

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

Total script time: 29.81 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/dbd0ded44b09b27/output.txt

Total script time: 60.00 mins

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

@Snuffleupagus
Copy link
Collaborator

Snuffleupagus commented Mar 28, 2025

Given that all invocations of this method now use the same TypedArray, it's quite easy to accidentally introduce subtle bugs because of it (as seen in even the first version of this patch).

Obviously the memory reduction is important here, but from a developer and reviewer perspective it seems that we'll now need to be very careful to not accidentally "mess up" when using this. Obviously it's not used in lots of places, but it does feel like a somewhat brittle situation and I wonder if there's anything that can be done to reduce the risk of future bugs?

@calixteman
Copy link
Contributor Author

Given that all invocations of this method now use the same TypedArray, it's quite easy to accidentally introduce subtle bugs because of it (as seen in even the first version of this patch).

Obviously the memory reduction is important here, but from a developer and reviewer perspective it seems that we'll now need to be very careful to not accidentally "mess up" when using this. Obviously it's not used in lots of places, but it does feel like a somewhat brittle situation and I wonder if there's anything that can be done to reduce the risk of future bugs?

I'm obliged to agree with you mainly because I had to fix such a bug while writing this patch.
Anyway I'll try to figure out a way to reduce the risk. If you any good ideas...

@Snuffleupagus
Copy link
Collaborator

Snuffleupagus commented Mar 28, 2025

I'm obliged to agree with you mainly because I had to fix such a bug while writing this patch.
Anyway I'll try to figure out a way to reduce the risk. If you any good ideas...

Is getImageSmoothingEnabled the worst case here?
What if we instead changed singularValueDecompose2dScale to require that you also pass in the Float32Array that the value is placed into, since it'd be completely risk-free to have all those getImageSmoothingEnabled invocations share just one TypedArray (defined globally in the canvas.js file)?

However, for the cases in pattern_helper.js it might not be that much of an issue if they used unique Float32Arrays for each invocation?

@calixteman calixteman force-pushed the simplif_singular_decomposition branch from 87b8ba5 to f70bd4c Compare March 30, 2025 20:13
@calixteman
Copy link
Contributor Author

/botio test

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

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

Live output at: http://54.241.84.105:8877/5a1dbc72ca933b6/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Received

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

Live output at: http://54.193.163.58:8877/7927c61f61ca00d/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Failed

Full output at http://54.241.84.105:8877/5a1dbc72ca933b6/output.txt

Total script time: 30.54 mins

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

Image differences available at: http://54.241.84.105:8877/5a1dbc72ca933b6/reftest-analyzer.html#web=eq.log

@calixteman calixteman force-pushed the simplif_singular_decomposition branch from f70bd4c to a1b1ed0 Compare March 30, 2025 21:03
@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/7927c61f61ca00d/output.txt

Total script time: 60.00 mins

… memory

In using the Firefox profiler (with JS allocations tracking) and wuppertal.pdf, I noticed
we were using a bit too much memory for a function which is supposed to just compute 2 numbers.
The memory used by itself isn't so important but having a too much objects lead to waste some time
to gc them.

So this patch aims to simplify it a bit.
@calixteman calixteman force-pushed the simplif_singular_decomposition branch from a1b1ed0 to 6e9fbd9 Compare March 31, 2025 08:28
@Snuffleupagus
Copy link
Collaborator

/botio browsertest

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Received

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

Live output at: http://54.193.163.58:8877/ea6962279be1780/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

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

Live output at: http://54.241.84.105:8877/1e9f57d7b805d1a/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/1e9f57d7b805d1a/output.txt

Total script time: 16.13 mins

  • Regression tests: Passed

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me, thank you.

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/ea6962279be1780/output.txt

Total script time: 29.74 mins

  • Regression tests: Passed

@calixteman calixteman merged commit a4950c0 into mozilla:master Mar 31, 2025
9 checks passed
@calixteman calixteman deleted the simplif_singular_decomposition branch March 31, 2025 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants