PERF: improve performance of read_dataframe if a filter is used - #577
Conversation
…ance-of-read_dataframe
…ance-of-read_dataframe
…ance-of-read_dataframe
…ance-of-read_dataframe
…ance-of-read_dataframe
jorisvandenbossche
left a comment
There was a problem hiding this comment.
I don't know if it is worth the added complexity, but in theory the following optimization might be possible: check if the driver supports fast count, and in the case there are no filters, that count should be a cheap lookup (like GPKG without any filtering), and at that point actually populate num_features. That would avoid using the growing chunk size in those cases (and we could directly read the entire data or directly use the max chunk size)
According to my tests when I wrote the PR, I didn't measure a significant difference between chunking or not for the case where no filtering was done, but it is not difficult to shortcut this case, so I added it. |
jorisvandenbossche
left a comment
There was a problem hiding this comment.
Looks good! Just two suggestions for clarifying comments for the future reader
|
(and needs to fix the merge conflicts) |
…ance-of-read_dataframe
In
read_dataframewithout arrow, the number of rows of the result was counted first, and then the full data was read.Especially when using a filter, counting the rows can take significant time.
This PR avoids doing the rowcount before reading to improve performance by reading the results in chunks till no more rows are returned from the dataset. For the new zealand building outlines geopackage (3.3 million rows) this gives these results:
where="ST_NPOINTS(st_buffer(geom, 10)) > 2000"(returning 9 rows) took 82 s, now 45 s.