Skip to content

Commit 0234638

Browse files
authored
feat: rework validations (#4)
* feat: enhance algorithm * feat: enhance algorithm * test: add tests * publish
1 parent b70edc7 commit 0234638

39 files changed

Lines changed: 6051 additions & 200 deletions

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 1.8.0
2+
3+
- Major performance improvements to the compiled validation pipeline
4+
- Inline type-checks for simple leaf schemas (string, optional string, nullable string) eliminating closure call overhead
5+
- Flatten nested pure objects into a single closure with direct map traversal
6+
- Capture error reporter directly in compiled closures, removing virtual dispatch
7+
- Benchmarks: Flat Object **18M ops/s** (+3x), Nested Object **9.5M ops/s** (+4x), Array Object **12M ops/s** (+3x)
8+
19
## 1.7.2
210

311
- Keep vine rules accross many validations

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ensuring that data complies with an expected format before it is used, which red
2020
| 🔄 Data Transformation | Trim, normalize, and transform values during validation |
2121
| 🚧 Null Safety | Full support for nullable and optional fields |
2222
| ⚙️ Composable | Compiled and reusable schemas |
23-
| ⚡ Fast Performance | ~ 3 000 000 ops/s |
23+
| ⚡ Fast Performance | ~ 18 000 000 ops/s |
2424
| 📦 Extremely small size | Package size `< 21kb` |
2525
| 🚀 OpenApi reporter | Export your schemas as OpenApi spec |
2626

@@ -107,6 +107,19 @@ final reporter = vine.openApi.report(schemas: {'MySchema': schema});
107107
print(reporter);
108108
```
109109

110+
## ⚡ Benchmark
111+
112+
Performance measured on compiled validators, single-threaded, Dart VM.
113+
114+
| Benchmark | Throughput |
115+
| ---------------------------- | -------------------- |
116+
| Flat Object | **18 191 374 ops/s** |
117+
| Nested Object | **9 562 766 ops/s** |
118+
| Array Object | **11 918 573 ops/s** |
119+
| Large Array (10 000 objects) | **11 ms** |
120+
121+
> Benchmarks are available in the `benchmark/` directory. Run them with `dart run benchmark/<name>.dart`.
122+
110123
## ❤️ Credit
111124

112125
I would like to thank [Harminder Virk](https://github.com/thetutlage) for all his open-source work on Adonis.js and for

benchmark/large_array.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import 'package:vine/src/vine.dart';
2+
3+
void main() {
4+
final validator = vine.compile(vine.array(
5+
vine.object({
6+
'id': vine.number(),
7+
'name': vine.string(),
8+
'email': vine.string().email(),
9+
}),
10+
));
11+
12+
final payload = List.generate(10000, (i) {
13+
return {
14+
'id': i,
15+
'name': 'User $i',
16+
'email': 'user$i@example.com',
17+
};
18+
});
19+
20+
final stopwatch = Stopwatch()..start();
21+
validator.validate(payload);
22+
stopwatch.stop();
23+
24+
print('Large Array (10k elements) : ${stopwatch.elapsedMilliseconds}ms');
25+
}

0 commit comments

Comments
 (0)