Skip to content

C extension - #97

Closed
halaxa wants to merge 24 commits into
masterfrom
ext-pr
Closed

C extension#97
halaxa wants to merge 24 commits into
masterfrom
ext-pr

Conversation

@halaxa

@halaxa halaxa commented May 6, 2023

Copy link
Copy Markdown
Owner

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

  • make ext-build-debug to make debug build of the C extension
  • make ext-build to make a production build of the C extension
  • make build (complete build) before pushing - it's run via github actions anyway

@codecov-commenter

codecov-commenter commented May 7, 2023

Copy link
Copy Markdown

Codecov Report

Patch coverage: 82.60% and project coverage change: -3.59 ⚠️

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

❗ 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
@@              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 Coverage Δ
src/ExtTokens.php 0.00% <0.00%> (ø)
src/IteratorLexerPOC.php 94.05% <94.05%> (ø)

... and 2 files with indirect coverage changes

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

@halaxa

halaxa commented May 30, 2025

Copy link
Copy Markdown
Owner Author

I am putting this on the back burner. The reason is the current release 1.2.3 brought first iteration of pure PHP optimizations that even slightly outperform this C implementation. And by my preliminary tests there's still a significant window for improvements in the second iteration that will be hopefully coming soon. To make a C extension makes sense when there's really no way to go further in pure PHP, which is currently not the case.

@halaxa halaxa closed this May 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants