From 62bf9ce03e559e42e0b700263973d89896e02e29 Mon Sep 17 00:00:00 2001 From: Filip Halaxa Date: Wed, 2 Mar 2022 21:53:56 +0100 Subject: [PATCH] Compilation optimizations --- Makefile | 5 ++++- .../0.15.2-5828ae2/jsonmachine_exttokens.zep.json | 10 +++++----- ext/jsonmachine/ext/jsonmachine/exttokens.zep.c | 2 +- ext/jsonmachine/jsonmachine/exttokens.zep | 2 +- test/performance/testPerformance.php | 5 ++++- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index d0a574a..8927ff3 100644 --- a/Makefile +++ b/Makefile @@ -121,8 +121,11 @@ zephir: ## Build JSON Machine's PHP extension "\ cd /json-machine/ext/jsonmachine \ && zephir fullclean \ - && zephir build \ + && zephir generate \ + && zephir compile --no-dev \ + && zephir install --no-dev \ && zephir stubs \ && cd /json-machine \ && vendor/bin/phpunit \ + && php test/performance/testPerformance.php \ " diff --git a/ext/jsonmachine/.zephir/0.15.2-5828ae2/jsonmachine_exttokens.zep.json b/ext/jsonmachine/.zephir/0.15.2-5828ae2/jsonmachine_exttokens.zep.json index 87d7a5e..0085724 100644 --- a/ext/jsonmachine/.zephir/0.15.2-5828ae2/jsonmachine_exttokens.zep.json +++ b/ext/jsonmachine/.zephir/0.15.2-5828ae2/jsonmachine_exttokens.zep.json @@ -723,7 +723,7 @@ { "type": "if", "expr": { - "type": "list", + "type": "unlikely", "left": { "type": "property-access", "left": { @@ -731,22 +731,22 @@ "value": "this", "file": "\/json-machine\/ext\/jsonmachine\/jsonmachine\/exttokens.zep", "line": 63, - "char": 22 + "char": 30 }, "right": { "type": "variable", "value": "escaping", "file": "\/json-machine\/ext\/jsonmachine\/jsonmachine\/exttokens.zep", "line": 63, - "char": 31 + "char": 40 }, "file": "\/json-machine\/ext\/jsonmachine\/jsonmachine\/exttokens.zep", "line": 63, - "char": 31 + "char": 40 }, "file": "\/json-machine\/ext\/jsonmachine\/jsonmachine\/exttokens.zep", "line": 63, - "char": 33 + "char": 40 }, "statements": [ { diff --git a/ext/jsonmachine/ext/jsonmachine/exttokens.zep.c b/ext/jsonmachine/ext/jsonmachine/exttokens.zep.c index 8ff6fa8..5cd13a5 100644 --- a/ext/jsonmachine/ext/jsonmachine/exttokens.zep.c +++ b/ext/jsonmachine/ext/jsonmachine/exttokens.zep.c @@ -181,7 +181,7 @@ PHP_METHOD(JsonMachine_ExtTokens, next) ZEPHIR_INIT_NVAR(&byte); zephir_substr(&byte, &_6$$3, zephir_get_intval(&_7$$3), 1 , 0); zephir_read_property(&_9$$3, this_ptr, ZEND_STRL("escaping"), PH_NOISY_CC | PH_READONLY); - if (zephir_is_true(&_9$$3)) { + if (UNEXPECTED(zephir_is_true(&_9$$3))) { if (0) { zephir_update_property_zval(this_ptr, ZEND_STRL("escaping"), &__$true); } else { diff --git a/ext/jsonmachine/jsonmachine/exttokens.zep b/ext/jsonmachine/jsonmachine/exttokens.zep index 2336708..775c94c 100644 --- a/ext/jsonmachine/jsonmachine/exttokens.zep +++ b/ext/jsonmachine/jsonmachine/exttokens.zep @@ -60,7 +60,7 @@ class ExtTokens implements \Iterator return; } let byte = substr(this->chunk, this->chunkIndex, 1); - if (this->escaping) { + if unlikely this->escaping { let this->escaping = false; let this->tokenBuffer = this->tokenBuffer . byte; let this->chunkIndex++; diff --git a/test/performance/testPerformance.php b/test/performance/testPerformance.php index d8d6c92..8ab81d7 100644 --- a/test/performance/testPerformance.php +++ b/test/performance/testPerformance.php @@ -2,7 +2,10 @@ declare(strict_types=1); +use JsonMachine\ExtTokens; +use JsonMachine\FileChunks; use JsonMachine\Items; +use JsonMachine\Parser; require_once __DIR__.'/../../vendor/autoload.php'; @@ -20,7 +23,7 @@ $decoders = [ return Items::fromFile($file, ['debug' => true]); }, 'Items::fromFile() - ext' => function ($file) { - return new \JsonMachine\Parser(); + return new Parser(new ExtTokens((new FileChunks($file))->getIterator())); }, 'json_decode()' => function ($file) { return json_decode(stream_get_contents(fopen($file, 'r')), true);