Skip to content

Speed up Vector.fromList - #188

Merged
gyrdym merged 1 commit into
masterfrom
cursor/speed-up-vector-from-list-0f4f
Sep 12, 2026
Merged

gyrdym merged 1 commit into
masterfrom
cursor/speed-up-vector-from-list-0f4f

Conversation

@gyrdym

@gyrdym gyrdym commented Sep 12, 2026

Copy link
Copy Markdown
Owner

Specialize Vector.fromList copying by the runtime type of the source list.

Previously every element went through List<num> indexing plus toDouble(), including when the source was already a Float32List/Float64List or List<double>. That kept the copy loop polymorphic and forced an extra conversion even when it was unnecessary.

The constructor now dispatches to typed helpers:

  • Float32List / Float64List: setRange (contiguous copy)
  • List<double>: direct assignment, no toDouble()
  • other List<num>: existing toDouble() path

On 10,000,000 elements, mixed-type runs in one isolate went from ~62/72/87 ms (List<double> / typed list / List<int>) to ~51/29/32 ms. Official 1e8-element benchmarks: List<double> 5.4s, Float32List 1.9s.

Float64x2Vector was regenerated from the Float32x4Vector template. Version bumped to 13.12.9.

Open in Web Open in Cursor 

Specialize list copying by source type so Float32List/Float64List uses
setRange, List<double> skips toDouble(), and other List<num> keeps the
generic conversion path.

Co-authored-by: Ilia Gyrdymov <gyrdym@users.noreply.github.com>
@gyrdym
gyrdym marked this pull request as ready for review September 12, 2026 21:07
@gyrdym
gyrdym merged commit 05eee8f into master Sep 12, 2026
1 of 2 checks passed
@gyrdym
gyrdym deleted the cursor/speed-up-vector-from-list-0f4f branch September 12, 2026 21:24
gyrdym added a commit that referenced this pull request Sep 13, 2026
Specialize list copying by source type so Float32List/Float64List uses
setRange, List<double> skips toDouble(), and other List<num> keeps the
generic conversion path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants