Path.swift icon indicating copy to clipboard operation
Path.swift copied to clipboard

ls() sorting is expensive...

Open ConfusedVorlon opened this issue 4 months ago • 2 comments

I was surprised to find that when profiling my app - I'm getting significant hangs with Path.ls()

I can see that you added .sorted() in https://github.com/mxcl/Path.swift/issues/58

First comment is that the doc is wrong - it states:

 Same as the `ls` command ∴ output is ”shallow” and unsorted.

Profiling a running app, I'm seeing 0.6 seconds spent doing locale-specific sorting for a not-particularly-huge directory, and a surprisingly large cost for the compactMap()

Image

Not sure what the right approach would be here. I'll probably add an unsorted_ls() command for my own use.

Possible options:

  • Remove the comment that output is unsorted
  • Flag that sorting can be expensive in the docs
  • ListDirectoryOptions: add an unsorted option ??
  • Add a separate unsorted command

ConfusedVorlon avatar Aug 09 '25 19:08 ConfusedVorlon

Not sure how this happened but yeah docs are wrong. I can update the docs and we could certainly remove the sorted() for a major version bump.

mxcl avatar Oct 30 '25 15:10 mxcl

I think removing as a default would be a good plan. Makes sense that it is a version bump.

ConfusedVorlon avatar Nov 01 '25 19:11 ConfusedVorlon