title: Is this a proper (performance-wise) way of scanning directories and caching paths to an array?
body: <h2>What am I trying to do</h2>
  
  <p>I'm trying to scan a disk and save (cache) all the paths of files and directories into an array so that I could perform a quick filename / directory name search later on.</p>
  
  <h2>Implementation</h2>
  
  <p>I'm using a Node.js module called <a href="https://www.npmjs.com/package/walkdir" rel="nofollow noreferrer">walkdir</a>.</p>
  
  <pre><code>cacheDisk () {
    let searchDir = 'C:/'
    let cache = []
  
    let options = {
      "max_depth": 5,       // only recurse down to max_depth. if you need more than no_recurse
      "track_inodes": true  // should be used with max_depth to prevent infinite loop. On windows or with hardlinks some files are not emitted due to inode collision.
    } 
  
    let paths = walkdir(searchDir, options, (path) =&gt; {
      cache.push(path)
    })
    .on('end', () =&gt; {
      console.log(cache)
      this.findItem(cache)
    })
  },
  
  findItem (cache) {
    let filename = 'file_1.txt'
    const matches = cache.filter(element =&gt; element.includes(filename))
    console.log(matches)
  }
  </code></pre>
  
  <h2>Questions / Problems:</h2>
  
  <p>FYI: I only need it to work in the latest Chrome (it's an Electron app)</p>
  
  <ul>
  <li>Is using <code>cache.push(path)</code> a good way (performance-wise) to save paths to the array or is the module already doing it for me and I'm just repeating this action on every iteration? It takes about 30 seconds and 500-800 MB of RAM on a core i7 to finish that caching operation for my ssd with 1 million paths</li>
  </ul>
  
  <hr>
  
  <ul>
  <li>Is using <code>cache.filter(element =&gt; element.includes(filename))</code> a good / safe way to find an element in an array that can potentially be ~10,000,000 paths in length?</li>
  </ul>
  
  <hr>
  
  <ul>
  <li>When I'm trying to scan disk's root (e.g. <code>C:/</code>) I get 2 slashes after the disk letter in every path (e.g. <code>C:\\Program Files\test</code>). But when I'm scanning something like <code>C:/test/</code> everything is fine. I guess that's Node's doing? How do I avoid that? (do I just replace all <code>\\</code> with <code>\</code> in all the paths afterwards? e.g. <code>cache.replace(/\\\\/g, "\\")</code>)</li>
  </ul>