halaxa / json-machine

Efficient, easy-to-use, and fast PHP JSON stream parser
Apache License 2.0
1.1k stars 65 forks source link

C extension #97

Open halaxa opened 1 year ago

halaxa commented 1 year ago

This is the first (at least publicly available 😁) working iteration of jsonmachine php extension. Its primary goal for the time being is to accelerate the most called PHP code by replacing it with c implementation. It currently implements only a single function which just simply parses JSON tokens. Its algorithm is basically mirrored from its PHP counterpart which is not optimal. Yet thanks to it the whole lib performs about 2x as fast as without it. With JIT enabled it's only about 1.6 times faster. There is tremendous potential though. This is my longest C code ever written and my first experiment with writing a PHP extension. Any feedback is welcome. It would be ideal to test it on some real and large datasets if anyone is interested. Valrgind says all memory leaks are fixed. If anyone is into C or better yet into Zend C API, feel free to suggest improvements.

Run

codecov-commenter commented 1 year ago

Codecov Report

Patch coverage: 82.60% and project coverage change: -3.59 :warning:

Comparison is base (68f5151) 100.00% compared to head (2e14840) 96.41%.

:exclamation: Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #97 +/- ## ============================================= - Coverage 100.00% 96.41% -3.59% - Complexity 184 219 +35 ============================================= Files 17 19 +2 Lines 526 641 +115 ============================================= + Hits 526 618 +92 - Misses 0 23 +23 ``` | [Impacted Files](https://app.codecov.io/gh/halaxa/json-machine/pull/97?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Filip+Halaxa) | Coverage Δ | | |---|---|---| | [src/ExtTokens.php](https://app.codecov.io/gh/halaxa/json-machine/pull/97?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Filip+Halaxa#diff-c3JjL0V4dFRva2Vucy5waHA=) | `0.00% <0.00%> (ø)` | | | [src/IteratorLexerPOC.php](https://app.codecov.io/gh/halaxa/json-machine/pull/97?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Filip+Halaxa#diff-c3JjL0l0ZXJhdG9yTGV4ZXJQT0MucGhw) | `94.05% <94.05%> (ø)` | | ... and [2 files with indirect coverage changes](https://app.codecov.io/gh/halaxa/json-machine/pull/97/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Filip+Halaxa)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.