Skip to content

[R] Reading wide files with per-column R metadata is slow #34319

Open

Description

@devinrkeane

Describe the bug, including details regarding any error messages, version, and platform.

I run pretty straight forward usage of read_parquet in several workflows at work. This has been a tremendous upgrade from using rds files with the same content for all the reasons arrow exists. Some of our datasets are wider than longer, which isnt great for parquet, but we usually only need a small subset.

I updated to arrow v11.0.0.2 yesterday and noticed that the identical workflows are loading files 50-60x slower.

A benchmark are selectively choosing 200 columns from a (3400 rows x 16000 column dataset, each column containing two text attributes)
~300ms with 9.0.0
~17000ms using v11.0.0.2.

Ubuntu 8-core intel i7

If I save the file I read from v9 saving with v11, then re-read with v11, it's the same , ~17 seconds

On the mac (M1 10-core) it's about 12 seconds.

I understand there are some significant changes under the hood with c++ under the v10 updates but based on the update notes no action would be required for doing anything fancy with ubuntu (I have gcc v9.4) or mac (clang v13).

Any idea what's going on? We store thousands of parquet files so wondering if we should avoid >= v11.

Sorry if this is mislabeled as a bug, but it seems like one to me as I havent changed anything else but systems meet the requirements.

here's a reprex:

library(arrow)
library(microbenchmark)

# fake data, 3500x16000 with attributes
test_data <- as.data.frame(
    lapply(setNames(1:16000, paste0("col", 1:16000)), function(x) {
    col <- sample(c(1:5, NA), 3500, replace = TRUE)
    levels(col) <- paste("level", 1:4)
    attr(col, "text") <- "test question text"
    col
  })
)

# write out the file somewhere
file <- "~/Desktop/test_data_v9.parquet"

### using arrow 9.0.0
packageVersion('arrow')
arrow::write_parquet(test_data, file)

### benchmark
microbenchmark::microbenchmark(
  arrow::read_parquet(file, col_select = 1:200), times = 10
)

### NOW SWITCH to arrow 11.0.0.2 just from the 9.0.0 data
packageVersion('arrow')
microbenchmark::microbenchmark(
  arrow::read_parquet(file, col_select = 1:200), times = 10
)

### now re-create, save, re-read using all v11
packageVersion('arrow')
file2 <- "~/Desktop/test_data_v11.parquet"
arrow::write_parquet(test_data, file2)

### benchmark
microbenchmark::microbenchmark(
  arrow::read_parquet(file2, col_select = 1:200), times = 10
)

Component(s)

R

Activity

  1. assignUser commented on Feb 24, 2023

    @assignUser
    Member

    Hello thanks for the detailed report!

    I am able to reproduce the issue, my times are overall a bit faster (192ms for 9.0.0 read) but 192ms -> 5s is still an unacceptable regression.

    r$> packageVersion('arrow')
        microbenchmark::microbenchmark(
          arrow::read_parquet(file, col_select = 1:200), times = 10
        )
    [1] '11.0.0.2'
    Unit: seconds
                                              expr      min       lq     mean   median       uq      max neval
     arrow::read_parquet(file, col_select = 1:200) 5.736177 5.993478 6.068209 6.093701 6.165921 6.355394    10
    
  2. assignUser commented on Feb 24, 2023

    @assignUser
    Member

    Actually same issue exists in 10.0.0

    packageVersion('arrow')
        microbenchmark::microbenchmark(
          arrow::read_parquet(file, col_select = 1:200), times = 10
        )
    [1] '10.0.0'
    Unit: seconds
                                              expr      min       lq     mean  median       uq      max neval
     arrow::read_parquet(file, col_select = 1:200) 6.135635 6.225003 6.312112 6.28199 6.361715 6.578094    10
    
  3. assignUser commented on Feb 24, 2023

    @assignUser
    Member

    col_select does not make a difference which I am pretty sure it should?

    r$> packageVersion('arrow')
        microbenchmark::microbenchmark(
          arrow::read_parquet("test_data_v10.parquet"), times = 2
        )
    [1] '10.0.0'
    Unit: seconds
                                             expr      min       lq     mean   median       uq      max neval
     arrow::read_parquet("test_data_v10.parquet") 6.363889 6.363889 6.422011 6.422011 6.480134 6.480134     2
    
    r$> packageVersion('arrow')
        microbenchmark::microbenchmark(
          arrow::read_parquet("test_data_v10.parquet", col_select = 1:200), times = 2
        )
    [1] '10.0.0'
    Unit: seconds
                                                                 expr      min       lq   mean median      uq     max neval
     arrow::read_parquet("test_data_v10.parquet", col_select = 1:200) 6.134009 6.134009 6.1936 6.1936 6.25319 6.25319     2
    
  4. changed the title [-]v11.0.0.2 extremely slow with parquet files written in v9.0.0[/-] [+][R] v11.0.0.2 extremely slow with parquet files written in v9.0.0[/+] on Feb 24, 2023
  5. assignUser commented on Feb 24, 2023

    @assignUser
    Member

    I get the same slow 6 seconds for 9.0.0 when I remove col_select, so it seems the issue existed before but was hidden for small number of cols.

  6. devinrkeane commented on Feb 24, 2023

    @devinrkeane
    Author

    thanks for responding so quickly! yeah I also tried with 20 columns and it didnt seem to affect anything performance wise, which previously (and expected) did matter a great deal.

  7. jorisvandenbossche commented on Feb 24, 2023

    @jorisvandenbossche
    Member

    I don't directly see a similar issue with pyarrow. Using the low-level reader (and a private method to be able to pass column indices directly instead of column names, to mimic what happens in R):

    In [1]: import pyarrow.parquet as pq
    
    In [2]: %timeit pq.ParquetFile("test_data.parquet").reader.read_all(column_indices=list(range(200)))
    146 ms ± 22 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
    

    That's with pyarrow 9.0, and I see basically the same for pyarrow 10.0.

    So maybe something changed with how the col_select keyword is being used?

  8. westonpace commented on Feb 24, 2023

    @westonpace
    Member

    Yes, I think so. @assignUser and I discussed this externally and noticed that the slowdown is likely R-specific

  9. paleolimbot commented on Feb 24, 2023

    @paleolimbot
    Member

    It's almost certainly these two lines:

    arrow/r/R/parquet.R

    Lines 56 to 59 in 1c483e4

    if (!quo_is_null(col_select)) {
    # infer which columns to keep from schema
    sim_df <- as.data.frame(reader$GetSchema())
    indices <- eval_select(col_select, sim_df) - 1L

    It's a little complicated to support both dplyr-like selection and speed here. Perhaps we need a workaround (like col_select = I(1:200)) to signal that a user wants to circumvent dplyr syntax sugar here?

  10. paleolimbot commented on Mar 9, 2023

    @paleolimbot
    Member

    A good workaround is probably just to use the ParquetFileReader directly:

    library(arrow, warn.conflicts = FALSE)
    #> Some features are not enabled in this build of Arrow. Run `arrow_info()` for more information.
    
    n_col <- 16000
    many_cols <- rep(list(1L), n_col)
    names(many_cols) <- paste0("col", seq_len(n_col))
    many_cols <- as.data.frame(many_cols)
    
    temp_parquet <- tempfile()
    write_parquet(many_cols, temp_parquet)
    
    system.time(read_parquet(temp_parquet, col_select = 1:200))
    #>    user  system elapsed 
    #>   5.863   0.534   6.375
    
    system.time({
      reader <- ParquetFileReader$create(temp_parquet)
      as.data.frame(reader$ReadTable(1:200))
    })
    #>    user  system elapsed 
    #>   0.220   0.007   0.207

    Perhaps the best fix here is a docs fix to suggest that this is possible/desirable? I would prefer that to adding more complexity to the implementation.

  11. jorisvandenbossche commented on Apr 6, 2023

    @jorisvandenbossche
    Member

    Is this something that is critical for 12.0?

  12. thisisnic commented on Apr 6, 2023

    @thisisnic
    Member

    @jorisvandenbossche It's not a blocker as we have a workaround.

  13. added
    Status: needs champion
    and removed
    Status: needs champion
    on Sep 24, 2026
  14. thisisnic commented on Sep 24, 2026

    @thisisnic
    Member

    Note: this comment was written by Claude Code (an AI assistant) at my request, after I asked it to check whether this issue still applies. I have reviewed the findings but the measurements and analysis are its own.

    I re-ran this on current main (1f789ff) to see whether it still applies. The short answer is that the col_select regression described in the original report is gone, but the reproducer is still slow for a different reason.

    With 16000 plain integer columns and no attributes, read_parquet(file, col_select = 1:200) takes about 0.15 s and reading all columns takes about 0.27 s. So the eval_select path that was suspected above is no longer a problem.

    The reproducer in this issue attaches levels and text attributes to every column, and that is where the time now goes. With 16000 such columns and 10 rows:

    elapsed
    as.data.frame(reader$ReadTable(1:200)) 1.28 s
    read_parquet(file, col_select = 1:200) 1.34 s
    tab$metadata$r alone, on the 200 column table 1.24 s
    read_parquet(file), all columns 10.5 s

    Two separate costs, both in R metadata handling and both scaling with the number of columns in the file rather than the number selected:

    1. Unserialising and sanitising the R metadata costs about 1.2 s per read regardless of col_select, because the table still carries metadata for all 16000 columns and safe_r_metadata() walks all of it in R:

      safe_r_metadata(out)
      . This was added in GH-42143: [R] Sanitize R metadata #41969, so it postdates the original report and is why the ParquetFileReader workaround above no longer helps much for data like this.

    2. Applying the per-column metadata costs a further 9 s when reading all columns, because the loop assigns into the data frame with x[[name]] <- on every iteration, copying the whole 16000 column frame each time:

      arrow/r/R/metadata.R

      Lines 178 to 182 in 1f789ff

      if (length(names(x)) && !is.null(columns_metadata) && !all(map_lgl(columns_metadata, is.null))) {
      for (name in intersect(names(columns_metadata), names(x))) {
      x[[name]] <- apply_arrow_r_metadata(x[[name]], columns_metadata[[name]])
      }
      }
      . GH-48057: [R] Slow reading performance caused by apply_arrow_r_metadata() looping through all columns, including NULL ones #48104 added an early exit for the case where no column has metadata, so it does not help here.

    I think this should stay open, but the title no longer describes the problem. Suggest retitling to something like "[R] Reading wide files with per-column R metadata is slow" and treating the two costs above as the work items. The second one is a small fix: collect the modified columns and assign once after the loop.

  15. changed the title [-][R] v11.0.0.2 extremely slow with parquet files written in v9.0.0[/-] [+][R] Reading wide files with per-column R metadata is slow[/+] on Sep 24, 2026
  16. added
    Status: confirmed
    on Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: RPriority: CriticalStatus: confirmedType: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions