I made some small changes, mostly to the matrix_factorization.pyx file, that drastically improve performance of the SVD and SVDpp algorithms. Most of the speed-up is evident in the SVDpp algorithm.
Most of the improvement comes from rewriting some loop constructs to avoid Python code as much as possible. This mostly involved changing for _ in to while constructs, please see matrix_factorization.pyx for more context.
On my machine (M1 MacBook Air) the benchmarks produce the following results:
Using the above table, along with the original benchmarks, we can determine that when switching from the 100k dataset to the 1M dataset the:
original SVD algorithm becomes 12.1x times slower, new becomes 12x slower.
original SVDpp becomes 19.26x slower, new becomes 20.61x slower
original NMF becomes 10.07x slower, new becomes 11x slower
Honestly, I'm not exactly sure why NMF is faster... Both the original code and the new code were compiled from source before running the benchmarks.
The difference with SVDpp might need to be investigated, but considering a base speed-up of 13.35x the reduced performance as the dataset size increases might be a worthwhile tradeoff.
Note: I haven't written any new tests, since fundamentally the algorithm remains unchanged. All tests that passed before my changes still pass after my changes (roughly 2x as fast).
I made some small changes, mostly to the
matrix_factorization.pyx
file, that drastically improve performance of the SVD and SVDpp algorithms. Most of the speed-up is evident in the SVDpp algorithm.Most of the improvement comes from rewriting some loop constructs to avoid Python code as much as possible. This mostly involved changing
for _ in
towhile
constructs, please seematrix_factorization.pyx
for more context.On my machine (M1 MacBook Air) the benchmarks produce the following results:
Original (current) version
Using the above table, along with the original benchmarks, we can determine that when switching from the 100k dataset to the 1M dataset the:
Honestly, I'm not exactly sure why NMF is faster... Both the original code and the new code were compiled from source before running the benchmarks.
The difference with SVDpp might need to be investigated, but considering a base speed-up of 13.35x the reduced performance as the dataset size increases might be a worthwhile tradeoff.
Note: I haven't written any new tests, since fundamentally the algorithm remains unchanged. All tests that passed before my changes still pass after my changes (roughly 2x as fast).