You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
2.0.5: Reuse PHP's interned 1-character and empty strings
Because we're using the simdjson C module, we know the length before we
need to allocate strings, so this is cheap to check.
This saves time in the following areas for 0 and 1 byte strings:
- PHP doesn't need to allocate a temporary string and initialize it
- PHP doesn't need to free the temporary string
- PHP doesn't need to compute the hash of the temporary string
- String comparisons are faster when strings are the exact same interned
string
- Memory usage is reduced because the string representation is reused
- CPU caches may already have this interned string
- If all array keys are interned strings, then php can skip the step of
freeing array keys when garbage collecting the array.
* This tests decoding an array with 100 objects where keys are single-char strings and empty strings.
15
+
*
16
+
* In simdjson, those are optimized for memory usage in php 7.2+ by using php's interned string constants instead of brand new strings.
17
+
* (json_decode doesn't do that but could - when using the simdjson C module it's quicker since the length is known before we need to allocate memory for the internal PHP string representation (zend_string))
18
+
*
19
+
* Note that in this benchmark, PHP garbage collecting the array returned by simdjson_decode can skip over the array keys,
20
+
* because none of the keys were reference counted.
0 commit comments