• Heath Borders's avatar
    [path_list.rb] Improve performance of read_file_system · ad94f543
    Heath Borders authored
    * Used a simple `String.slice` to create relative paths instead of `path.relative_path_from(root)`. Since we already know that all files must exist under `root` (because we globbed `absolute_paths` from `root`), we can just remove the first `root.to_s.length + 1` characters from an `absolute_path` to get a `relative_path`.
    * Partition `dirs` and `files` first since we already get an array of absolute paths back from `Pathname.glob`, removing unnecessary string concat: `File.directory?(root + path)`
    * Used `lazy` arrays to reduce array iteration.
    
    I [profiled my code before the change](https://github.com/CocoaPods/CocoaPods/files/477973/call-stack.zip).
    I [profiled my new code again](https://github.com/CocoaPods/CocoaPods/files/478512/call-stack2.html.zip), and `read_file_system` practically disappears.
    
    previous:
    
    ```
    real     0m59.095s
    user     0m46.133s
    sys      0m2.360s
    ```
    
    now:
    
    ```
    real     0m23.712s
    user     0m14.492s
    sys      0m2.030s
    ```
    ad94f543
Name
Last commit
Last update
.github Loading commit data...
bin Loading commit data...
examples Loading commit data...
lib Loading commit data...
spec Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
.gitmodules Loading commit data...
.kick Loading commit data...
.rubocop.yml Loading commit data...
.rubocop_cocoapods.yml Loading commit data...
.rubocop_todo.yml Loading commit data...
.travis.yml Loading commit data...
.yardopts Loading commit data...
CHANGELOG.md Loading commit data...
CODE_OF_CONDUCT.md Loading commit data...
CONTRIBUTING.md Loading commit data...
Dangerfile Loading commit data...
Gemfile Loading commit data...
Gemfile.lock Loading commit data...
LICENSE Loading commit data...
README.md Loading commit data...
Rakefile Loading commit data...
cocoapods.gemspec Loading commit data...