GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Faster subset by dvd101x · Pull Request #3467 · josdejong/mathjs

Conversation

@dvd101x

@dvd101x dvd101x commented Apr 26, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

Hi,

This improves the speed of subset by following a recommendation in the TODO comments and other recursion improvements.

These are the results

image

develop
======
subset(matrix, rows and columns)         1.89 µs   ±0.13%
subset(array, rows and columns)          4.89 µs   ±0.25%
subset(matrix, booleans and columns)     2.15 µs   ±0.25%
subset(array, booleans and columns)      5.09 µs   ±0.14%
subset(matrix, columns and booleans)     2.15 µs   ±0.35%
subset(array, columns and booleans)      5.13 µs   ±0.34%
subset(matrix, range and rows)           1.19 µs   ±0.20%
subset(array, range and rows)            4.19 µs   ±0.16%
subset(matrix, range and all)            1.73 µs   ±0.20%
subset(array, range and all)             4.70 µs   ±0.16%
subset(matrix, all and range)            2.32 µs   ±0.20%
subset(array, all and range)             5.24 µs   ±0.19%
subset(matrix, all and all)              4.69 µs   ±0.26%
subset(array, all and all)               7.64 µs   ±0.20%

this pr
=====
subset(matrix, rows and columns)         1.23 µs   ±0.15%
subset(array, rows and columns)          4.17 µs   ±0.19%
subset(matrix, booleans and columns)     1.37 µs   ±0.18%
subset(array, booleans and columns)      4.30 µs   ±0.50%
subset(matrix, columns and booleans)     1.37 µs   ±0.18%
subset(array, columns and booleans)      4.29 µs   ±0.20%
subset(matrix, range and rows)           0.82 µs   ±0.20%
subset(array, range and rows)            3.74 µs   ±0.16%
subset(matrix, range and all)            0.81 µs   ±0.26%
subset(array, range and all)             3.64 µs   ±0.14%
subset(matrix, all and range)            1.10 µs   ±0.37%
subset(array, all and range)             3.97 µs   ±0.30%
subset(matrix, all and all)              1.64 µs   ±0.20%
subset(array, all and all)               4.43 µs   ±0.17%

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
dvd101x added 4 commits April 25, 2025 20:44
@dvd101x
Include tests
cac8d81
@dvd101x
Formatting error
4b69d56
@dvd101x
Fixed rangeAll
9016dcd
@dvd101x
Faster setting in DenseMatrix
4912877
josdejong
josdejong reviewed Apr 26, 2025
View reviewed changes

@josdejong josdejong left a comment

Copy link
Copy Markdown
Owner

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.

That is a neat improvement David! You can't quit improving the performance can't you? 😜

I made a few inline comments, can you have a look at those?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

dvd101x reacted with laugh emoji
All reactions
  • 😄 1 reaction
Comment thread src/type/matrix/DenseMatrix.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/type/matrix/DenseMatrix.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/benchmark/subset.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

@dvd101x

dvd101x commented Apr 26, 2025

Copy link
Copy Markdown
Collaborator Author

Haha yes, found this while checking something else and couldn't resist.

Thank you for your comments, I will test returning back to matrix.map and matrix.forEach because in the latest commit I didn't see the improvement in performance I expected when making a subset with replacement. Also will add tests for subset with replacement.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dvd101x
Returned the use of matrix.map and matrix.forEach
3e7ec7c
@josdejong

josdejong commented May 7, 2025

Copy link
Copy Markdown
Owner

@dvd101x so what is the current status? Does the PR still yield good performance improvements after your latest commits, returning to use x.map?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dvd101x

dvd101x commented May 15, 2025

Copy link
Copy Markdown
Collaborator Author

Hi Jos, thanks for the response. I will just add a big matrix benchmark and I think that will be it.

After your comments and the benchmarks, I think the current implementations are ok. Returning the use of map will benefit readability and would affect performance for big matrices in chrome and in safari a bit less. Firefox would be still ok.

The current logic after many tests I think it's ok to follow this suggestion:

  • for stuff that could be big (like matrices or arrays) avoid the use of array.map and array.forEach, and implement something like a for as done here or on matrix.map and matrix.forEach.
  • For small stuff like the size of an array or an index I think it's ok to use array.map and array.forEach

So I will only add a benchmark for a bigMatrix and all the comments will be addressed.

Thanks for your patience and follow up.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dvd101x
Added tests for big matrices
2535dd0
@dvd101x

dvd101x commented May 15, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator Author

Hi, I included a few benchmarks for bigger matrices, and the difference is also significant. More so when the ranges for the subset are further away from 0. In which case the benefits are some of the highest.

Sin título

With this I think all comments are addressed and it's ready to be merged.

PR 3467

subset(bigMatrix, rows and columns)                   1.42 µs   ±0.34%
subset(bigArray, rows and columns)                    1.40 µs   ±0.30%
subset(bigMatrix, range and columns)                  1.74 µs   ±0.88%
subset(bigArray, rows and range)                      1.84 µs   ±0.38%

develop

subset(bigMatrix, rows and columns)                   1.93 µs   ±0.30%
subset(bigArray, rows and columns)                    1.95 µs   ±1.64%
subset(bigMatrix, range and columns)                  3.29 µs   ±0.47%
subset(bigArray, rows and range)                      4.06 µs   ±0.24%
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@josdejong

josdejong commented May 21, 2025

Copy link
Copy Markdown
Owner

👌 Nice, I like how this turned out, this is a significant improvement indeed! Thanks David

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@josdejong
josdejong merged commit 920d0ca into develop May 21, 2025
@josdejong
josdejong deleted the faster-slicing branch May 21, 2025 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@josdejong josdejong josdejong left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@dvd101x @josdejong
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.