thisisnic commented on issue #38087: URL: https://github.com/apache/arrow/issues/38087#issuecomment-7172452346
I used an AI agent to time and profile this on pyarrow 26.0.1, and I've reviewed the results. ---------------- 🤖 : The gap is still there on pyarrow 26.0.1, at about 2x for a 100-column read (not 4-5x), and it mostly disappears when reading all columns. `pq.ParquetFile(path).read(columns=...)` uses the same C++ `FileReader` path as the C++ program above, so it is the comparison used here. File: float64 columns, 2000 rows, `row_group_size=1000`, no dictionary, no statistics, `use_threads=False`, best of 5. | Columns in file | 100 columns: `pq.read_table` | 100 columns: `pq.ParquetFile().read` | Ratio | All columns: ratio | |---|---|---|---|---| | 1,000 | 10 ms | 6 ms | 1.8 | 1.4 | | 10,000 | 80 ms | 41 ms | 2.0 | 1.1 | | 20,000 | 161 ms | 84 ms | 1.9 | 1.1 | The footer is not parsed twice. Counting calls with gdb breakpoints during one 100-column read of the 20,000-column file: | Function | `pq.ParquetFile().read` | `pq.read_table` | |---|---|---| | `parquet::FileMetaData::Make` | 1 | 1 | | `parquet::arrow::FileReader::Make` | 1 | 2 | | `parquet::arrow::SchemaManifest::Make` | 1 | 4 | | `arrow::ipc::ReadSchema` | 2 | 8 | | `arrow::MakeArrayOfNull` | 0 | 20,000 | So the extra time is per-column work on the whole schema that the dataset path repeats, even though only 100 columns are read: - `SchemaManifest::Make` (the Parquet-to-Arrow schema conversion for all 20,000 columns) runs four times. Three are under `ParquetFileFragment::EnsureCompleteMetadata` (`cpp/src/arrow/dataset/file_parquet.cc`), reached when `pq.ParquetDataset` asks for `fragment.physical_schema`: once in `FileReader::Make`, once in `reader->GetSchema()`, and once in `GetSchemaManifest()`. The fourth is a second `FileReader::Make` when the scan opens the file. - `FragmentToBatches` (`cpp/src/arrow/dataset/scanner.cc`) builds an empty null array for every field of the dataset schema, 20,000 here, to make the default batch for an empty fragment. In a sampling profile (py-spy with native frames), `SchemaManifest::Make` is about 32% of the `pq.read_table` time and `MakeArrayOfNull` about 14%; the percentages are approximate. Until that is improved, `pq.ParquetFile(path).read(columns=...)` avoids the overhead for a single file. I've relabelled this as an enhancement, as the results are correct and this is a performance improvement. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
