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

Faster xdr reader #32

Merged
merged 19 commits into from
Jan 16, 2024
Merged

Faster xdr reader #32

merged 19 commits into from
Jan 16, 2024

Conversation

trossi
Copy link
Contributor

@trossi trossi commented Dec 5, 2023

This PR adds faster reader for files in xdr format. Full arrays are read directly with numpy instead of reading element by element. As a positive side effect, deprecated xdrlib isn't needed anymore.

Related to #31. I have cherry-picked and rebased commits related to xdr reader improvements to this PR. There are also some structural changes that are open for discussion, for example, xdr reader is moved to rdata/io/xdr.py to simplify separation between different readers like (upcoming) rdata/io/ascii.py. @vnmabus Could you review?

rdata/io/xdr.py Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Dec 5, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (d4c1d83) 92.02% compared to head (3a4631e) 91.98%.
Report is 11 commits behind head on develop.

Files Patch % Lines
rdata/parser/_parser.py 96.15% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop      #32      +/-   ##
===========================================
- Coverage    92.02%   91.98%   -0.05%     
===========================================
  Files            6        7       +1     
  Lines         1104     1086      -18     
===========================================
- Hits          1016      999      -17     
+ Misses          88       87       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@trossi
Copy link
Contributor Author

trossi commented Dec 8, 2023

Here is approximate timing data for reference:

Array size (MiB) Time to read before this PR (s) Time to read with this PR (s)
16 1.2 0.3
32 2.2 0.3
64 4.2 0.3
128 8.0 0.4
256 18.5 0.5
512 39.4 0.8
1024 77.3 1.5

This data was created with the following (in bash):

  1. Generate test data (without compression to skip time spent in decompression): for i in {1..7}; do n=$(( 2 ** $i )); Rscript -e "saveRDS(runif(n=$n*1024**2), file='array_$i.rds', compress=FALSE)"; done
  2. Read and measure time: for i in {1..7}; do echo $i; time -p python -c "from rdata.parser import parse_file; parse_file('array_$i.rds')"; done

LICENSE Outdated Show resolved Hide resolved
pyproject.toml Show resolved Hide resolved
rdata/io/xdr.py Outdated Show resolved Hide resolved
rdata/io/xdr.py Outdated Show resolved Hide resolved
rdata/io/xdr.py Outdated Show resolved Hide resolved
rdata/io/xdr.py Outdated Show resolved Hide resolved
rdata/io/xdr.py Outdated Show resolved Hide resolved
rdata/parser/_parser.py Outdated Show resolved Hide resolved
rdata/parser/_parser.py Outdated Show resolved Hide resolved
Copy link
Owner

@vnmabus vnmabus left a comment

Choose a reason for hiding this comment

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

Sorry for the delay in accepting this. I was on vacation and had a "forced" digital detox. Approving and merging now.

pyproject.toml Show resolved Hide resolved
@vnmabus vnmabus merged commit f81ed84 into vnmabus:develop Jan 16, 2024
14 of 15 checks passed
@trossi
Copy link
Contributor Author

trossi commented Jan 16, 2024

Sorry for the delay in accepting this. I was on vacation and had a "forced" digital detox. Approving and merging now.

No problem, thank you for merging! I hope you had a relaxing vacation!

I'll open a PR for ASCII reader next.

@vnmabus
Copy link
Owner

vnmabus commented Jan 25, 2024

Here is approximate timing data for reference:

Just to let you know: I added your example (but limited to 5 iterations) as an asv benchmark to the package, to check for future performance regressions. I also added a new testing module (currently undocumented) to retrieve and execute R snippets from strings, so that each test can have its associated R snippet for creating the data, instead of a big script for all.

@trossi trossi mentioned this pull request Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants