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

Optimization and performance improvements #14

Open
cristianlivella opened this issue Nov 25, 2021 · 4 comments
Open

Optimization and performance improvements #14

cristianlivella opened this issue Nov 25, 2021 · 4 comments
Labels
performance Performance related issue

Comments

@cristianlivella
Copy link
Owner

cristianlivella commented Nov 25, 2021

Currently, processing reports with several thousand transactions takes many seconds.

There are definitely functions that are executed several times unnecessarily, and values that could be cached.

It is necessary to review which functions are the most computationally heavy and improve and/or cache them.

@cristianlivella cristianlivella added the enhancement New feature or request label Nov 25, 2021
@cristianlivella
Copy link
Owner Author

This is a screenshot of a performance report made using Blackfire, with a set of ~100000 transactions (60000 purchases, 25000 sales and 15000 expenses, with 100 different cryptocurrencies).

86% of the time is taken by the initial parsing and computation made on the transactions file.
In particular, the 25% is taken by the parsing with PhpSpreadsheet, and the 53% by the research of purchase transactions, for the calculation of capital gains.

The findRelativePurchases and getPurchaseAmountRemaining definitely have a huge margin for improvement, as at the moment particularly inefficient loops are performed.

Concerning the loading time required by PhpSpreadsheet, we need to check if we can improve something, or we could at least, during the first request, save the array in a faster readable format (JSON? serialize?) for the following requests.

@cristianlivella
Copy link
Owner Author

cristianlivella commented Nov 26, 2021

Using the same input file as before, just parsing from CSV to array takes about 6.5 seconds on my laptop.

Saving the array to a json file doesn't take any significant additional time.

Successive reads of the array from the json file only take about 0.1 seconds, so this is definitely a change to make.

Encryption and decryption with AES does not seem to affect the loading time significantly, so the json file can be encrypted with the same key as the source file, before being saved.

@cristianlivella cristianlivella added performance Performance related issue and removed enhancement New feature or request labels Nov 26, 2021
@cristianlivella cristianlivella changed the title Optimization and performance improvement Optimization and performance improvements Nov 26, 2021
@cristianlivella
Copy link
Owner Author

With the last improvements, the processing time for the sample file with ~100000 transactions decreased from 32 to 6 seconds on my laptop (-80%).

There's definitely still something that can be improved, but for now I'm satisfied.

This is the updated call graph from Blackfire:

@cristianlivella
Copy link
Owner Author

cristianlivella commented Nov 27, 2021

With the last improvements, the processing time for the sample file with ~100000 transactions decreased from 6 to 3 seconds on my laptop (-50%).

(click for high res)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance related issue
Projects
None yet
Development

No branches or pull requests

1 participant