[PERF] Improve performace of read_csv with memory_map=True when file encoding is UTF-8 - #43787
Merged
Merged
Conversation
Contributor
|
@michal-gh yeah if you can run the existing asv's and report here (and you might need to add one to cover this case). cc @twoertwein |
twoertwein
approved these changes
Sep 28, 2021
twoertwein
left a comment
Member
There was a problem hiding this comment.
You might want to add a whatsnew entry for this. This is quite an impressive speedup!
| @skip_pyarrow | ||
| def test_readcsv_memmap_utf8(all_parsers): | ||
| lines = [] | ||
| for lnum in range(0x20, 0x10080, 0x80): |
Member
There was a problem hiding this comment.
Maybe add a comment what these magic numbers represent or what the block is doing.
Contributor
Author
There was a problem hiding this comment.
Added explanatory variables and comment.
michal-gh
added a commit
to michal-gh/pandas
that referenced
this pull request
Oct 2, 2021
michal-gh
added a commit
to michal-gh/pandas
that referenced
this pull request
Oct 2, 2021
michal-gh
added a commit
to michal-gh/pandas
that referenced
this pull request
Oct 2, 2021
michal-gh
added a commit
to michal-gh/pandas
that referenced
this pull request
Oct 2, 2021
michal-gh
added a commit
to michal-gh/pandas
that referenced
this pull request
Oct 2, 2021
jreback
requested changes
Oct 3, 2021
jreback
left a comment
Contributor
There was a problem hiding this comment.
do we have an asv which covers this (if its straightforward to do)
michal-gh
added a commit
to michal-gh/pandas
that referenced
this pull request
Oct 3, 2021
michal-gh
force-pushed
the
perf-readcsv
branch
from
October 5, 2021 15:57
960ddb5 to
944c73b
Compare
Contributor
Author
|
The last commit above includes asv perf test. On my machine, running asv's io.csv returns: I also corrected the whatsnew file. |
jreback
approved these changes
Oct 6, 2021
Contributor
|
thanks @michal-gh very nice! |
gasparitiago
pushed a commit
to gasparitiago/pandas
that referenced
this pull request
Oct 9, 2021
rhshadrach
pushed a commit
to rhshadrach/pandas
that referenced
this pull request
Oct 10, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR improves performance of read_csv with memory_map=True and a UTF-8-encoded file by eliminating unnecessary
decode()call. The code below demonstrates the speed improvement:On my machine the results are:
Without patch:
With patch:
The improved code runs in ~65% of time of the current code.
The spedup depends on the contents of the file; the test code above creates a 182 MB file containing almost all of Unicode Plane 0 and a several of Plane 1 characters UTF-8-encoded in 1, 2, 3 and 4 bytes; in this respect, it is a worst case. I also tested this patch on my 8.8 GB CSV file consisting of 1 and 2-byte encoded characters and the code ran in ~75% of time of the current code.