php / php/php-src

`json_encode` can use SIMD

Open
#17,672 13 comments 0 reactions 0 assignees View on GitHub

@ndossche is already working on this.

Since Feb 8, 2025.

  • #17734 by @ndossche — open
Extension: json Feature Status: Verified
Dominant language
C
Stars
40.4k
Forks
8.2k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

The current json_encode implementation [1] iterates on every string character.

I belive there is a potential to utilize SIMD to copy multiple characters to the output string as long as they are not to-be-escaped.

Benchmark: https://3v4l.org/XeJTn/rfc#vgit.master

This can improve performace on applications that do a lot of JSON encoding.

[1] https://github.com/php/php-src/blob/php-8.4.3/ext/json/json_encoder.c#L411

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with ext/json/json_encoder.c around line 411 and compare the current character-by-character encoding with the benchmark at https://3v4l.org/XeJTn/rfc#vgit.master. Review open pull request #17734 before starting, since it is already addressing this issue. Done means a SIMD-based implementation is evaluated against the existing benchmark without changing escaping behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, php
Domain
performance
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.