-
Notifications
You must be signed in to change notification settings - Fork 1.7k
jsonEncode() is (almost) 40% slower than the Node.js counterpart #51779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Slightly better script.dart: import "dart:convert";
void main() {
final List<int> list = List<int>.generate(
10000000,
(final int i) => i,
growable: false,
);
final Stopwatch watch = Stopwatch()..start();
const JsonEncoder().convert(list);
watch.stop();
print("Dart time: ${watch.elapsedMilliseconds} ms");
} this script is took, |
This comment was marked as off-topic.
This comment was marked as off-topic.
Related: |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This is most likely caused by us going Not that it really matters unless you want to serialise large amount of data (at which point you probably should not be using JSON in the first place). FWIW |
(I have marked most of the server-side Dart discussion as off topic for this issue, and respectfully encourage to continue it through other community channels). |
I'd love to have an Let's see if we can find somewhere to add that. (Still need parsing to/from strings too, for all the usual uses, but avoiding going through strings when not necessary can be more performant.) |
Related to #51619 |
I am testing Dart capabilities as a web server and I am doing some easy tests against Node.js
I have written a simple program using the Alfred web server and I stumbled upon this issue:
dart.convert
/jsonEncode()
is slower than the Node.js counterpart.This is the Dart code of my server, it simply gets a
num
parameter and generates a list ofint
s with the number.In the end, it returns a JSON. The Alfred library calls
dart.convert
/jsonEncode
on it.This is the server code (Node.js version is exactly the same, only using ExpressJS):
These are some tests I have run on both servers using restest
NOTE: Dart version is an executable compiled with
dart compile exe
command.Node.js version
Dart version
As you can see, from second request and beyond the Node.js version is faster than the compiled Dart version.
Everything is related to
jsonEncode()
, because if I change the server code, removing the list to be encoded in this way:The Dart version becomes the fastest, as you can see from these benchmarks:
Node.js version
Dart version
Dart SDK version: 2.19.3 (stable) (Tue Feb 28 15:52:19 2023 +0000) on "linux_x64"
I am attaching two very simple scripts (one for Dart and one for Node.js) that do not require any dependency, the Dart one is like this:
Node.js version executes in: 246 ms
Dart version executes in: 615 ms
count.tar.gz
The text was updated successfully, but these errors were encountered: