A high-performance PHP C++ extension for ASON (Array-Schema Object Notation) — SIMD-accelerated (SSE2/AVX2/NEON), zero-copy parsing, direct Zend API with no intermediate layers.
ASON separates schema from data, eliminating repetitive keys found in JSON:
JSON (100 tokens):
{"users":[{"id":1,"name":"Alice","active":true},{"id":2,"name":"Bob","active":false}]}
ASON (~35 tokens, 65% saving):
[{id:int, name:str, active:bool}]:(1,Alice,true),(2,Bob,false)
| Scenario | json_encode | ason_encode | Speedup |
|---|---|---|---|
| Flat struct × 100 | 3.66 ms | 0.88 ms | 4.16x |
| Flat struct × 500 | 15.02 ms | 4.03 ms | 3.73x |
| Flat struct × 1000 | 31.89 ms | 8.66 ms | 3.68x |
| Flat struct × 5000 | 152.69 ms | 56.63 ms | 2.70x |
| Scenario | json_decode | ason_decode | Speedup |
|---|---|---|---|
| Flat struct × 100 | 7.13 ms | 2.93 ms | 2.43x |
| Flat struct × 500 | 35.35 ms | 16.03 ms | 2.21x |
| Flat struct × 1000 | 69.06 ms | 29.83 ms | 2.32x |
| Flat struct × 5000 | 347.81 ms | 154.45 ms | 2.25x |
| Scenario | json_decode | ason_decode | Speedup |
|---|---|---|---|
| 10 Companies | 30.38 ms | 0.42 ms | 72.34x |
| 50 Companies | 148.92 ms | 1.92 ms | 77.51x |
| 100 Companies | 325.97 ms | 3.88 ms | 83.91x |
| Scenario | JSON | ASON Text | ASON Bin | Saving (Text/Bin) |
|---|---|---|---|---|
| Flat struct × 100 | 12,071 B | 5,614 B | 7,446 B | 53% / 38% |
| Flat struct × 5000 | 612,808 B | 287,851 B | 372,250 B | 53% / 39% |
| 100 Companies | 431,612 B | 231,011 B | 251,830 B | 46% / 42% |
- Pure C++ Extension — direct Zend API, no intermediate layers, no FFI overhead
- SIMD-accelerated — SSE2/AVX2 (x86_64) and NEON (ARM64) with scalar fallback
- Zero-copy parsing — string scanning without heap allocation where possible
- PHP 8.4 compatible — built for the latest PHP with proper arginfo
- Binary format — compact binary serialization for maximum throughput
- Pretty formatting — smart indentation with configurable width
- IDE support — PHP stubs included for autocomplete and type checking
cd ason-php
phpize
./configure --enable-ason
make -j$(nproc)
# Optional: install system-wide
sudo make install; php.ini
extension=ason.soOr use per-command:
php -d extension=path/to/modules/ason.so your_script.php| Function | Description |
|---|---|
ason_encode($data) |
Encode to ASON format |
ason_decode($string) |
Decode ASON string to PHP value |
ason_encodeBinary($data) |
Encode to ASON binary format |
ason_decodeBinary($str, $schema) |
Decode binary with type schema |
ason_encodeTyped($data) |
Encode with type annotations in schema |
ason_encodePretty($data) |
Encode with pretty formatting |
ason_encodePrettyTyped($data) |
Encode with pretty formatting + type annotations |
<?php
// Serialize a struct (associative array)
$user = ['id' => 1, 'name' => 'Alice', 'active' => true];
$ason = ason_encode($user);
// → "{id,name,active}:(1,Alice,true)"
// With type annotations
$typed = ason_encodeTyped($user);
// → "{id:int,name:str,active:bool}:(1,Alice,true)"
// Deserialize
$decoded = ason_decode($ason);
// → ['id' => 1, 'name' => 'Alice', 'active' => true]
// Vec of structs — schema written once
$users = [
['id' => 1, 'name' => 'Alice', 'active' => true],
['id' => 2, 'name' => 'Bob', 'active' => false],
];
$vec = ason_encode($users);
// → "[{id,name,active}]:(1,Alice,true),(2,Bob,false)"<?php
$user = ['id' => 42, 'name' => 'Alice', 'active' => true];
// Encode to binary (compact, fast)
$bin = ason_encodeBinary($user);
echo strlen($bin); // 18 bytes vs 36 bytes text
// Decode with type schema
$decoded = ason_decodeBinary($bin, [
'id' => 'int',
'name' => 'str',
'active' => 'bool',
]);<?php
$users = [
['id' => 1, 'name' => 'Alice', 'active' => true],
['id' => 2, 'name' => 'Bob', 'active' => false],
];
echo ason_encodePrettyTyped($users);
// [{id:int, name:str, active:bool}]:
// (1, Alice, true),
// (2, Bob, false)Once the extension is built, you can run the included examples and benchmarks directly from the command line:
# Run basic examples
php -d extension=modules/ason.so examples/basic.php
# Run complex nested structure examples
php -d extension=modules/ason.so examples/complex.php
# Run performance benchmarks (ASON vs json_encode/json_decode)
php -d extension=modules/ason.so examples/bench.php- Zero key repetition — Schema is written once; data rows carry only values
- Direct Zend API — No intermediate data structures; directly constructs PHP
zvalandHashTable - SIMD string scanning — SSE2/AVX2/NEON vectorized character detection (16 bytes/cycle)
- Fast number formatting — Two-digit lookup table, fast-path float formatting
- Schema-driven parsing — Positional field mapping with O(1) access, no per-row key hashing
- Minimal allocation — Stack-based schema parsing (max 64 fields, zero heap)
Basic test coverage:
- ✅ Struct encode/decode roundtrip
- ✅ Typed schema encode
- ✅ Vec encode/decode roundtrip
- ✅ Pretty format (single struct, vec)
- ✅ Binary encode/decode roundtrip
- ✅ Nested structs
- ✅ Array fields
- ✅ Optional/null fields
- ✅ Special characters (quotes, escapes, newlines, tabs, backslashes)
- ✅ Comments parsing
- ✅ Multiline format
- ✅ Cross-compatibility with C++ format
- ✅ Large dataset (1000+ records)
Copy stubs/ason.php to your project for IDE autocomplete:
cp stubs/ason.php /path/to/your/project/.stubs/Then configure your IDE to include the stubs directory for autocompletion.
MIT