Skip to content

Improve performance of path_rel #519

Description

@orgadish

fs::path_rel is suprisingly slow on large vectors. I use it regularly on the FilePath output of read_csv(..., .id="FilePath"), where most of the vector is severely duplicated (# of total rows >> # files). This is one of the reasons I developed the deduped package in the first place.

There are 3 simple opportunities for performance improvement:

  1. Hoist starts <- path_split(start) out of the loop since start is guaranteed to be a single, fixed string.
  2. Deduplicate the paths vector before the loop to reduce the number of R loop iterations (same strategy as deduped package but using base R)
  3. Create internal version of path_common that takes the split pieces as arguments so that the splitting of all paths can be vectorized outside the R loop.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions