Skip to content

Commit 46814f6

Browse files
committed
wip
Signed-off-by: Dmitry Dygalo <[email protected]>
1 parent 624ab02 commit 46814f6

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

bindings/php/README.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,16 @@
99
## Performance
1010

1111
This library uses components from Mozilla's Servo project for CSS parsing and matching.
12-
Performance benchmarks show 3-9x faster execution than `tijsverkoyen/css-to-inline-styles`.
12+
Performance benchmarks show significant speed improvements over other popular PHP CSS inlining libraries.
1313

14-
The table below shows benchmark results comparing `css_inline` with `tijsverkoyen/css-to-inline-styles` on typical HTML documents:
14+
| | Size | `css_inline 0.15.0` | `css-to-inline-styles 2.3.0` | `emogrifier 7.3.0` |
15+
|-------------------|---------|---------------------|------------------------------|-------------------------|
16+
| Simple | 230 B | 5.99 µs | 28.06 µs (**4.68x**) | 137.85 µs (**23.01x**) |
17+
| Realistic email 1 | 8.58 KB | 102.25 µs | 313.31 µs (**3.06x**) | 637.75 µs (**6.24x**) |
18+
| Realistic email 2 | 4.3 KB | 71.98 µs | 655.43 µs (**9.10x**) | 2.32 ms (**32.21x**) |
19+
| GitHub Page† | 1.81 MB | 163.80 ms | ERROR | ERROR |
1520

16-
| | Size | `css_inline 0.15.0` | `tijsverkoyen/css-to-inline-styles 2.2.7` | Speedup |
17-
|-------------------|---------|---------------------|-------------------------------------------|---------|
18-
| Simple | 230 B | 5.99 µs | 28.06 µs | **4.68x** |
19-
| Realistic email 1 | 8.58 KB | 102.25 µs | 313.31 µs | **3.06x** |
20-
| Realistic email 2 | 4.3 KB | 71.98 µs | 655.43 µs | **9.10x** |
21-
| GitHub Page† | 1.81 MB | 163.80 ms | 8.22 ms* | N/A |
22-
23-
> † The GitHub page benchmark uses modern CSS that `tijsverkoyen/css-to-inline-styles` cannot process, resulting in skipped styles and an invalid comparison.
21+
† The GitHub page benchmark contains complex modern CSS that neither `css-to-inline-styles` nor `emogrifier` can process and didn't finish a single iteration in >10 minutes.
2422

2523
Please refer to the `benchmarks/InlineBench.php` file to review the benchmark code.
2624
The results displayed above were measured using stable `rustc 1.88` on PHP `8.4.10`.

bindings/php/benchmarks/InlineBench.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use PhpBench\Benchmark\Metadata\Annotations\ParamProviders;
66
use CssInline;
77
use TijsVerkoyen\CssToInlineStyles\CssToInlineStyles;
8-
8+
use Pelago\Emogrifier\CssInliner;
99

1010
class InlineBench
1111
{
@@ -16,6 +16,7 @@ public function __construct()
1616
$this->cssToInlineStyles = new CssToInlineStyles();
1717
ini_set('pcre.backtrack_limit', '10000000');
1818
ini_set('pcre.recursion_limit', '10000000');
19+
ini_set('memory_limit', '2048M');
1920
}
2021

2122
/**
@@ -34,6 +35,14 @@ public function benchCssToInlineStyles(array $params): void
3435
$this->cssToInlineStyles->convert($params['html']);
3536
}
3637

38+
/**
39+
* @ParamProviders("provideBenchmarkCases")
40+
*/
41+
public function benchEmogrifier(array $params): void
42+
{
43+
CssInliner::fromHtml($params['html'])->inlineCss()->render();
44+
}
45+
3746

3847
public function provideBenchmarkCases(): \Generator
3948
{

bindings/php/composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"ext-css_inline": "*"
99
},
1010
"require-dev": {
11+
"pelago/emogrifier": "^7.3",
1112
"phpbench/phpbench": "^1.4",
1213
"phpunit/phpunit": "^10.5",
1314
"tijsverkoyen/css-to-inline-styles": "^2.3"
@@ -23,6 +24,7 @@
2324
},
2425
"config": {
2526
"sort-packages": true,
26-
"optimize-autoloader": true
27+
"optimize-autoloader": true,
28+
"process-timeout": 0
2729
}
2830
}

bindings/php/phpbench.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"runner.path": "benchmarks",
44
"runner.php_config": {
55
"extension": "target/release/libcss_inline_php.so"
6-
}
6+
},
7+
"runner.timeout": 3600
78
}

0 commit comments

Comments
 (0)