     }
 
     DispatchQueue.main.async {
-      let result = Array(sorted[0...min(self.maxResultCount, sorted.count - 1)])
+      let result = Array(sorted[0...min(maxResultCount, sorted.count - 1)])
       self.openQuickly.reloadFileView(withScoredItems: result)
     }
   }
+
+  fileprivate let pattern: String
+  fileprivate let flatFileItems: [FileItem]
+  fileprivate let cwd: URL
+
+  fileprivate unowned let openQuickly: OpenQuicklyWindow
 }
+
+fileprivate let chunkSize = 100
+fileprivate let maxResultCount = 500


class OpenQuicklyFilterOperation: Operation {

  fileprivate let chunkSize = 100
  fileprivate let maxResultCount = 500

  fileprivate let pattern: String
  fileprivate let flatFileItems: [FileItem]
  fileprivate let cwd: URL

  fileprivate unowned let openQuickly: OpenQuicklyWindow

  init(forOpenQuickly openQuickly: OpenQuicklyWindow) {
    self.openQuickly = openQuickly
    self.pattern = openQuickly.pattern
    self.cwd = openQuickly.cwd as URL
    self.flatFileItems = openQuickly.flatFileItems

    super.init()

          return
        }

        let startIndex = min(idx * chunkSize, count)
        let endIndex = min(startIndex + chunkSize, count)

        let chunkedItems = self.flatFileItems[startIndex..<endIndex]
        let chunkedResult: [ScoredFileItem] = chunkedItems.flatMap {
