Extension method performance concerns #60649
Labels
area-dart-model
For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.
model-performance
Performance/memory issues in analyzer/cfe
type-performance
Issue relates to performance or code size
Maybe extension methods gets a bit slow, if you have many of them.
In
package:typed_sql
I model database queries using tuples with an expression objects for each column. SoQuery<(Expr<A>, Expr<B>, ...)>
represents a query returning rows with(A, B ...,)
. To make this work I have extension methods forQuery<(Expr<A>,)>
,Query<(Expr<A>, Expr<B>)>
, and so forth.Thus, I generate need$$N$$ extensions to support queries with up-to $$N$$ columns, well, actually to support joins I end up generating $$O(N^2)$$ extensions.
Arguably, this is a bit extreme, if$$N$$ gets too large. But for reasonably values of $$N$$ this shouldn't be a problem. However, I've noticed that if I scale up $$N$$ a bit, things become a bit slow.
Below you'll find a graph of the time it takes to run:
dart analyze lib/
,dart test/sqlite/sqlite_test.dart
(simple test with in-memory database, in Dart JIT mode),dart compile exe test/sqlite/sqlite_test.dart
.The graph also plots size of the generated code, do note that the non-generated code in
lib/
is around ~10k, and there is a few dependencies too.Raw numbers here:
This was generated with
Dart SDK version: 3.9.0-63.0.dev (dev) (Sun Apr 27 17:07:04 2025 -0700) on "linux_x64"
.Note that my code has$$O(N^2)$$ extension methods, and performance does seem to scale linear with the LOC count (lines of code). So maybe there is no problem at all, even if 31s seems a bit long to wait for 150k lines of code.
The text was updated successfully, but these errors were encountered: