Skip to content
This repository was archived by the owner on Mar 24, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions frameworks/Dart/dart3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ The tests were run with:

## Benchmark Variants

### JIT

Simplest possible implementation utilizing the standard Dart VM.
Results in the highest footprint both in terms of image size and memory consumption.
([source code](https://github.com/TechEmpower/FrameworkBenchmarks/tree/master/frameworks/Dart/dart3/dart_jit))

Test URLs:

- JSON: `http://localhost:8080/json`
- PLAINTEXT: `http://localhost:8080/plaintext`

### Native

Minimal implementation with the smallest resource footprint.
Expand Down
12 changes: 12 additions & 0 deletions frameworks/Dart/dart3/benchmark_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@
"language": "Dart",
"os": "Linux",
"database_os": "Linux"
},
"jit": {
"display_name": "dart3_jit",
"json_url": "/json",
"plaintext_url": "/plaintext",
"port": 8080,
"approach": "Stripped",
"classification": "Platform",
"database": "None",
"language": "Dart",
"os": "Linux",
"database_os": "Linux"
}
}]
}
3 changes: 1 addition & 2 deletions frameworks/Dart/dart3/dart3-aot.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ WORKDIR /app

ARG MAX_ISOLATES=8

COPY pubspec.yaml .
COPY dart_aot/bin/ bin/
COPY dart_aot/ .

RUN dart compile aot-snapshot bin/server.dart \
--define=MAX_ISOLATES=${MAX_ISOLATES} \
Expand Down
8 changes: 8 additions & 0 deletions frameworks/Dart/dart3/dart3-jit.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

FROM dart:3.11.0 AS build
WORKDIR /app

COPY dart_jit/ .

EXPOSE 8080
ENTRYPOINT ["dart", "run", "bin/server.dart"]
3 changes: 1 addition & 2 deletions frameworks/Dart/dart3/dart3.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
FROM dart:3.11.0 AS build
WORKDIR /app

COPY pubspec.yaml .
COPY dart_native/bin/ bin/
COPY dart_native/ .

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

Expand Down
21 changes: 4 additions & 17 deletions frameworks/Dart/dart3/dart_aot/bin/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ final _jsonEncoder = JsonUtf8Encoder();
/// belong to a secondary "worker group".
const _workerGroupTag = '--WORKER-GROUP';

/// The maximum duration allowed for a single HTTP request to be processed.
/// This prevents slow clients or stalled logic from blocking the isolate's
/// event loop indefinitely.
const _requestTimeout = Duration(seconds: 8);

void main(List<String> arguments) async {
/// Create a mutable copy of the fixed-length arguments list.
final args = [...arguments];
Expand Down Expand Up @@ -91,22 +86,14 @@ Future<void> _startServer(List<String> args) async {
server
..defaultResponseHeaders.clear()
/// Sets [HttpServer]'s [serverHeader].
..serverHeader = 'dart_aot';

/// Handles [HttpRequest]'s from [HttpServer].
await for (final request in server) {
/// Asynchronously processes each request with an 8-second safety deadline
/// to prevent stalled connections from blocking the isolate event loop.
await _handleRequest(request).timeout(
_requestTimeout,
onTimeout: () => _sendResponse(request, HttpStatus.requestTimeout),
);
}
..serverHeader = 'dart_aot'
/// Handles [HttpRequest]'s from [HttpServer].
..listen(_handleRequest);
}

/// Dispatches requests to specific test handlers. Wrapped in a try-catch
/// to ensure stable execution and guaranteed response delivery.
Future<void> _handleRequest(HttpRequest request) async {
void _handleRequest(HttpRequest request) {
try {
switch (request.uri.path) {
case '/json':
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: dartbenchmark
description: A benchmark of dart
name: dart_aot_benchmark
description: A benchmark of Dart
environment:
sdk: ^3.11.0

Expand Down
3 changes: 3 additions & 0 deletions frameworks/Dart/dart3/dart_jit/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include: package:lints/recommended.yaml
formatter:
trailing_commas: preserve
87 changes: 87 additions & 0 deletions frameworks/Dart/dart3/dart_jit/bin/server.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import 'dart:convert';
import 'dart:io';

/// The fixed TCP port used by the server.
/// Defined here for visibility and ease of configuration.
const _defaultPort = 8080;

/// A reusable instance of the UTF-8 JSON encoder to efficiently
/// transform Dart objects into byte arrays for HTTP responses.
final _jsonEncoder = JsonUtf8Encoder();

void main(List<String> args) async {
/// Binds the [HttpServer] on `0.0.0.0:8080`.
final server = await HttpServer.bind(
InternetAddress.anyIPv4,
_defaultPort,
);

server
..defaultResponseHeaders.clear()
/// Sets [HttpServer]'s [serverHeader].
..serverHeader = 'dart_jit'
/// Handles [HttpRequest]'s from [HttpServer].
..listen(_handleRequest);
}

/// Dispatches requests to specific test handlers. Wrapped in a try-catch
/// to ensure stable execution and guaranteed response delivery.
void _handleRequest(HttpRequest request) {
try {
switch (request.uri.path) {
case '/json':
_jsonTest(request);
break;
case '/plaintext':
_plaintextTest(request);
break;
default:
_sendResponse(request, HttpStatus.notFound);
}
} catch (e) {
_sendResponse(request, HttpStatus.internalServerError);
}
}

/// Completes the given [request] by writing the [bytes] with the given
/// [statusCode] and [type].
void _sendResponse(
HttpRequest request,
int statusCode, {
ContentType? type,
List<int> bytes = const [],
}) => request.response
..statusCode = statusCode
..headers.contentType = type
..headers.date = DateTime.now()
..contentLength = bytes.length
..add(bytes)
..close();

/// Completes the given [request] by writing the [response] as JSON.
void _sendJson(HttpRequest request, Object response) => _sendResponse(
request,
HttpStatus.ok,
type: ContentType.json,
bytes: _jsonEncoder.convert(response),
);

/// Completes the given [request] by writing the [response] as plain text.
void _sendText(HttpRequest request, String response) => _sendResponse(
request,
HttpStatus.ok,
type: ContentType.text,
bytes: utf8.encode(response),
);

/// Responds with the JSON test to the [request].
void _jsonTest(HttpRequest request) => _sendJson(
request,
const {'message': 'Hello, World!'},
);

/// Responds with the plaintext test to the [request].
void _plaintextTest(HttpRequest request) => _sendText(
request,
'Hello, World!',
);
8 changes: 8 additions & 0 deletions frameworks/Dart/dart3/dart_jit/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: dart_jit_benchmark
description: A benchmark of Dart
environment:
sdk: ^3.11.0

dev_dependencies:
lints: ^6.1.0

3 changes: 3 additions & 0 deletions frameworks/Dart/dart3/dart_native/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include: package:lints/recommended.yaml
formatter:
trailing_commas: preserve
21 changes: 4 additions & 17 deletions frameworks/Dart/dart3/dart_native/bin/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ const _defaultPort = 8080;
/// transform Dart objects into byte arrays for HTTP responses.
final _jsonEncoder = JsonUtf8Encoder();

/// The maximum duration allowed for a single HTTP request to be processed.
/// This prevents slow clients or stalled logic from blocking the isolate's
/// event loop indefinitely.
const _requestTimeout = Duration(seconds: 8);

void main(List<String> args) async {
/// Create an [Isolate] containing an [HttpServer]
/// for each processor after the first
Expand All @@ -38,22 +33,14 @@ Future<void> _startServer(List<String> args) async {
server
..defaultResponseHeaders.clear()
/// Sets [HttpServer]'s [serverHeader].
..serverHeader = 'dart_native';

/// Handles [HttpRequest]'s from [HttpServer].
await for (final request in server) {
/// Asynchronously processes each request with an 8-second safety deadline
/// to prevent stalled connections from blocking the isolate event loop.
await _handleRequest(request).timeout(
_requestTimeout,
onTimeout: () => _sendResponse(request, HttpStatus.requestTimeout),
);
}
..serverHeader = 'dart_native'
/// Handles [HttpRequest]'s from [HttpServer].
..listen(_handleRequest);
}

/// Dispatches requests to specific test handlers. Wrapped in a try-catch
/// to ensure stable execution and guaranteed response delivery.
Future<void> _handleRequest(HttpRequest request) async {
void _handleRequest(HttpRequest request) {
try {
switch (request.uri.path) {
case '/json':
Expand Down
8 changes: 8 additions & 0 deletions frameworks/Dart/dart3/dart_native/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: dart_native_benchmark
description: A benchmark of Dart
environment:
sdk: ^3.11.0

dev_dependencies:
lints: ^6.1.0

Loading