Skip to content
This repository was archived by the owner on Mar 24, 2026. It is now read-only.

Commit d1587be

Browse files
committed
add dart3-jit implementation
1 parent d5f0a2a commit d1587be

8 files changed

Lines changed: 131 additions & 36 deletions

File tree

frameworks/Dart/dart3/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ The tests were run with:
88

99
## Benchmark Variants
1010

11+
### JIT
12+
13+
### JIT
14+
15+
Simplest possible implementation utilizing the standard Dart VM.
16+
Results in the highest footprint both in terms of image size and memory consumption.
17+
([source code](https://github.com/TechEmpower/FrameworkBenchmarks/tree/master/frameworks/Dart/dart3/dart_jit))
18+
19+
Test URLs:
20+
21+
- JSON: `http://localhost:8080/json`
22+
- PLAINTEXT: `http://localhost:8080/plaintext`
23+
1124
### Native
1225

1326
Minimal implementation with the smallest resource footprint.

frameworks/Dart/dart3/benchmark_config.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
"language": "Dart",
2626
"os": "Linux",
2727
"database_os": "Linux"
28+
},
29+
"jit": {
30+
"display_name": "dart3_jit",
31+
"json_url": "/json",
32+
"plaintext_url": "/plaintext",
33+
"port": 8080,
34+
"approach": "Stripped",
35+
"classification": "Platform",
36+
"database": "None",
37+
"language": "Dart",
38+
"os": "Linux",
39+
"database_os": "Linux"
2840
}
2941
}]
3042
}

frameworks/Dart/dart3/dart3-aot.dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ WORKDIR /app
55
ARG MAX_ISOLATES=8
66

77
COPY pubspec.yaml .
8-
COPY dart_aot/bin/ bin/
8+
COPY dart_aot/ .
99

1010
RUN dart compile aot-snapshot bin/server.dart \
1111
--define=MAX_ISOLATES=${MAX_ISOLATES} \
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
FROM dart:3.11.0 AS build
3+
WORKDIR /app
4+
5+
COPY pubspec.yaml .
6+
COPY dart_jit/ .
7+
8+
EXPOSE 8080
9+
ENTRYPOINT ["dart", "run", "bin/server.dart"]

frameworks/Dart/dart3/dart3.dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM dart:3.11.0 AS build
33
WORKDIR /app
44

55
COPY pubspec.yaml .
6-
COPY dart_native/bin/ bin/
6+
COPY dart_native/ .
77

88
RUN dart compile exe bin/server.dart -o server
99

frameworks/Dart/dart3/dart_aot/bin/server.dart

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ final _jsonEncoder = JsonUtf8Encoder();
2525
/// belong to a secondary "worker group".
2626
const _workerGroupTag = '--WORKER-GROUP';
2727

28-
/// The maximum duration allowed for a single HTTP request to be processed.
29-
/// This prevents slow clients or stalled logic from blocking the isolate's
30-
/// event loop indefinitely.
31-
const _requestTimeout = Duration(seconds: 8);
32-
3328
void main(List<String> arguments) async {
3429
/// Create a mutable copy of the fixed-length arguments list.
3530
final args = [...arguments];
@@ -91,22 +86,14 @@ Future<void> _startServer(List<String> args) async {
9186
server
9287
..defaultResponseHeaders.clear()
9388
/// Sets [HttpServer]'s [serverHeader].
94-
..serverHeader = 'dart_aot';
95-
96-
/// Handles [HttpRequest]'s from [HttpServer].
97-
await for (final request in server) {
98-
/// Asynchronously processes each request with an 8-second safety deadline
99-
/// to prevent stalled connections from blocking the isolate event loop.
100-
await _handleRequest(request).timeout(
101-
_requestTimeout,
102-
onTimeout: () => _sendResponse(request, HttpStatus.requestTimeout),
103-
);
104-
}
89+
..serverHeader = 'dart_aot'
90+
/// Handles [HttpRequest]'s from [HttpServer].
91+
..listen(_handleRequest);
10592
}
10693

10794
/// Dispatches requests to specific test handlers. Wrapped in a try-catch
10895
/// to ensure stable execution and guaranteed response delivery.
109-
Future<void> _handleRequest(HttpRequest request) async {
96+
void _handleRequest(HttpRequest request) {
11097
try {
11198
switch (request.uri.path) {
11299
case '/json':
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import 'dart:convert';
2+
import 'dart:io';
3+
4+
/// The fixed TCP port used by the server.
5+
/// Defined here for visibility and ease of configuration.
6+
const _defaultPort = 8080;
7+
8+
/// A reusable instance of the UTF-8 JSON encoder to efficiently
9+
/// transform Dart objects into byte arrays for HTTP responses.
10+
final _jsonEncoder = JsonUtf8Encoder();
11+
12+
void main(List<String> args) async {
13+
/// Binds the [HttpServer] on `0.0.0.0:8080`.
14+
final server = await HttpServer.bind(
15+
InternetAddress.anyIPv4,
16+
_defaultPort,
17+
);
18+
19+
server
20+
..defaultResponseHeaders.clear()
21+
/// Sets [HttpServer]'s [serverHeader].
22+
..serverHeader = 'dart_jit'
23+
/// Handles [HttpRequest]'s from [HttpServer].
24+
..listen(_handleRequest);
25+
}
26+
27+
/// Dispatches requests to specific test handlers. Wrapped in a try-catch
28+
/// to ensure stable execution and guaranteed response delivery.
29+
void _handleRequest(HttpRequest request) {
30+
try {
31+
switch (request.uri.path) {
32+
case '/json':
33+
_jsonTest(request);
34+
break;
35+
case '/plaintext':
36+
_plaintextTest(request);
37+
break;
38+
default:
39+
_sendResponse(request, HttpStatus.notFound);
40+
}
41+
} catch (e) {
42+
_sendResponse(request, HttpStatus.internalServerError);
43+
}
44+
}
45+
46+
/// Completes the given [request] by writing the [bytes] with the given
47+
/// [statusCode] and [type].
48+
void _sendResponse(
49+
HttpRequest request,
50+
int statusCode, {
51+
ContentType? type,
52+
List<int> bytes = const [],
53+
}) => request.response
54+
..statusCode = statusCode
55+
..headers.contentType = type
56+
..headers.date = DateTime.now()
57+
..contentLength = bytes.length
58+
..add(bytes)
59+
..close();
60+
61+
/// Completes the given [request] by writing the [response] as JSON.
62+
void _sendJson(HttpRequest request, Object response) => _sendResponse(
63+
request,
64+
HttpStatus.ok,
65+
type: ContentType.json,
66+
bytes: _jsonEncoder.convert(response),
67+
);
68+
69+
/// Completes the given [request] by writing the [response] as plain text.
70+
void _sendText(HttpRequest request, String response) => _sendResponse(
71+
request,
72+
HttpStatus.ok,
73+
type: ContentType.text,
74+
bytes: utf8.encode(response),
75+
);
76+
77+
/// Responds with the JSON test to the [request].
78+
void _jsonTest(HttpRequest request) => _sendJson(
79+
request,
80+
const {'message': 'Hello, World!'},
81+
);
82+
83+
/// Responds with the plaintext test to the [request].
84+
void _plaintextTest(HttpRequest request) => _sendText(
85+
request,
86+
'Hello, World!',
87+
);

frameworks/Dart/dart3/dart_native/bin/server.dart

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ const _defaultPort = 8080;
1010
/// transform Dart objects into byte arrays for HTTP responses.
1111
final _jsonEncoder = JsonUtf8Encoder();
1212

13-
/// The maximum duration allowed for a single HTTP request to be processed.
14-
/// This prevents slow clients or stalled logic from blocking the isolate's
15-
/// event loop indefinitely.
16-
const _requestTimeout = Duration(seconds: 8);
17-
1813
void main(List<String> args) async {
1914
/// Create an [Isolate] containing an [HttpServer]
2015
/// for each processor after the first
@@ -38,22 +33,14 @@ Future<void> _startServer(List<String> args) async {
3833
server
3934
..defaultResponseHeaders.clear()
4035
/// Sets [HttpServer]'s [serverHeader].
41-
..serverHeader = 'dart_native';
42-
43-
/// Handles [HttpRequest]'s from [HttpServer].
44-
await for (final request in server) {
45-
/// Asynchronously processes each request with an 8-second safety deadline
46-
/// to prevent stalled connections from blocking the isolate event loop.
47-
await _handleRequest(request).timeout(
48-
_requestTimeout,
49-
onTimeout: () => _sendResponse(request, HttpStatus.requestTimeout),
50-
);
51-
}
36+
..serverHeader = 'dart_native'
37+
/// Handles [HttpRequest]'s from [HttpServer].
38+
..listen(_handleRequest);
5239
}
5340

5441
/// Dispatches requests to specific test handlers. Wrapped in a try-catch
5542
/// to ensure stable execution and guaranteed response delivery.
56-
Future<void> _handleRequest(HttpRequest request) async {
43+
void _handleRequest(HttpRequest request) {
5744
try {
5845
switch (request.uri.path) {
5946
case '/json':

0 commit comments

Comments
 (0)