← Back to list

Swoole's TypePHP, Tens to Hundreds of Times Faster than Native PHP, Will Be Open Sourced in the…

The `Swoole AOT` compiler project has now been officially renamed to TypePHP, and the beta version will be released in the second half of…

Chimin · 2026-06-20 13:08 · 50 claps · 3.5 min read paywalled
#swoole #php #web-development #php-developers #website
Open on Medium ↗
Wiki topics: 🌐 · Web Development 🔓 · Open Source

Swoole's TypePHP, Tens to Hundreds of Times Faster than Native PHP, Will Be Open Sourced in the Second Half of 2026

The Swoole AOT compiler project has now been officially renamed to TypePHP, and the beta version will be released in the second half of 2026, at which point the full source code will be open sourced.

TypePHP is a brand-new, strongly typed, statically compiled language with syntax fully compatible with PHP, but a completely different runtime approach. PHP relies on the ZendVM to compile code into opcode bytecodes and then dynamically interprets and executes them, while TypePHP directly compiles into binary machine instructions for execution.

In terms of computational performance, TypePHP is tens to hundreds of times faster than PHP. Compiled binary programs cannot be decompiled back to source code, providing a natural advantage in commercial software deployment and distribution. Additionally, TypePHP does not require writing C/C++ extensions as PHP does to gain low-level capabilities—it is based on the C++ ABI and can directly call .a / .lib static libraries or .so / .dll dynamic link libraries generated by statically compiled languages such as C/C++, Rust, and Golang. This makes TypePHP capable of developing native desktop software, games, system software, and low-level infrastructure.

You can view examples and download trial programs on the GitHub repository homepage to experience it in advance. The source code of the TypePHP project will be uploaded after the National Day holiday.

Compatibility with PHP

TypePHP's runtime retains the ZendVM. The main code is statically compiled into an executable file, while .php scripts can still be loaded and dynamically interpreted at runtime via require/include.

This is equivalent to a dual-engine drive: statically compiled machine instructions coexist with dynamically loaded interpreted scripts. This design ensures 100% compatibility of TypePHP with the PHP ecosystem, including:

*PHP extensions:* curl, mysqli, PDO, Swoole and other open source extensions, as well as self-developed C/C++ extensions, can all be used normally Composer: **All Composer packages can be loaded at runtime via the autoload mechanism

TypePHP Bootstrapping

The TypePHP project is entirely developed using the TypePHP language itself—consistent with the design philosophy of the Golang compiler being written in Go language and achieving self-hosting.

The first version runs on Zend PHP to compile and generate an Alpha version of the TypePHP compiler. Subsequent versions support dual mode: you can either compile with TypePHP itself or use Zend PHP for dynamic interpretation and execution. In the latest v0.2.3 version, all unit tests have passed for both the self-compiled version and the Zend PHP version.

TypePHP Extended Features

Compared to PHP, TypePHP introduces three additional core features.

▸ 1. Native Support for Scientific and Financial Computing

TypePHP natively includes three high-precision numeric types: BigInt, BigFloat, and Decimal, supporting unlimited-precision integers, high-precision floating-point operations, and high-precision lossless decimal floating-point operations respectively. They can be directly used in scientific computing and financial scenarios.

Decimal floating-point:

// After declaration, default floating-point literals will be parsed as Decimal type
use decimal_types;

function main() {
    $v1 = 0.1;
    $v2 = 0.2;
    // Outputs 0.3. In PHP, due to float precision issues, the result might be 0.30000000000000004
    echo $v1 + $v2;
}

Big integer arithmetic:

// After declaration, default integer literals will be parsed as BigInt type
use bigint_types;

function main() {
    $v = 2 ** 80;
    // Outputs 1208925819614629174706176
    // In PHP, because it exceeds PHP_INT_MAX, precision is lost and the result becomes a float
    echo $v;
}

▸ 2. Strongly Typed Containers

TypePHP provides 4 strongly typed containers, replacing the omnipotent array in PHP. In PHP, a single array structure cannot distinguish between a list and a map, nor can it constrain the types of keys and values. Strongly typed containers bring stronger determinism, better performance, and lower memory usage to programming.

// Key is string, Value is restricted to stdClass objects
$map = std::map(complex_types::type_string, stdClass::class);
$map["key"] = new stdClass;
$map["key"]->data = "hello";

▸ 3. Universal Method Call

TypePHP allows using the object method call syntax on values of any type. In addition to methods on built-in types, it also supports custom extension methods on types.

$a = 2;
// Call pow() on an integer to compute 2^80, convert to string, then get length
echo $a->pow(80)->toString()->length();

$b = "hello world!";
// Call split() on a string to split, then call contains() on the returned array to check if it contains an element
$b->split(' ')->contains("world");

Extension methods:

In addition to built-in methods, you can customize extension methods for any type:

function int_to_bytes(int $num): string {
    return ($num / 1024) . 'Kb';
}

$value = 92160;
// The compiler automatically matches int_to_bytes, outputs: 90Kb
echo $value->toBytes();

// Chain call: convert to string then call equals() to check value equality
var_dump($value->toBytes()->equals('90Kb'));
function str_sha1(string $str): string {
    return sha1($str);
}

$s = "test";
// Perform two successive sha1 hashes on $s
echo $s->sha1()->sha1();

메타데이터
post_id
9f3a50aa9ec5
slug
swooles-typephp-tens-to-hundreds-of-times-faster-than-native-php-will-be-open-sourced-in-the-9f3a50aa9ec5
url
https://medium.com/@githubdaily/swooles-typephp-tens-to-hundreds-of-times-faster-than-native-php-will-be-open-sourced-in-the-9f3a50aa9ec5
canonical_url
https://medium.com/@githubdaily/swooles-typephp-tens-to-hundreds-of-times-faster-than-native-php-will-be-open-sourced-in-the-9f3a50aa9ec5
author_url
https://medium.com/@githubdaily
status
ok
fetched_at
2026-07-17 08:48:32