Skip to content

Commit

Permalink
perf: avoid calling uniq on array of hashes
Browse files Browse the repository at this point in the history
closes #416

The comparison of `Hash` that is performed when calling `uniq` is
significantly slower than traversing all duplicates and then calling
`uniq` on an array of `String`.
  • Loading branch information
ElMassimo committed Nov 21, 2024
1 parent cfdb0be commit 3e6ad00
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions vite_ruby/lib/vite_ruby/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def resolve_entries(*names, **options)
entries = names.map { |name| lookup!(name, **options) }
script_paths = entries.map { |entry| entry.fetch("file") }

imports = dev_server_running? ? [] : entries.flat_map { |entry| entry["imports"] }.compact.uniq
imports = dev_server_running? ? [] : entries.flat_map { |entry| entry["imports"] }.compact
{
scripts: script_paths,
imports: imports.map { |entry| entry.fetch("file") }.uniq,
imports: imports.filter_map { |entry| entry.fetch("file") }.uniq,
stylesheets: dev_server_running? ? [] : (entries + imports).flat_map { |entry| entry["css"] }.compact.uniq,
}
end
Expand Down

0 comments on commit 3e6ad00

Please sign in to comment.