This PR adds some missing functionality and improved performance to PHP flatbuffers:
in PHP builder: finish with prefixed size, clear, and createBytesVector methods. I drew inspiration from TS.
added PHP IDL generator namer; partially addressed in #7491, and I continued that work.
for-loops replaced with substr_replace in createString and growByteBuffer. createBytesVector also uses this.
During internal testing, I noticed that tables using PHP keywords as names (e.g., bytes, string) would yield errors in the generated code because keywords cannot be used as class names despite their casing (also mentioned in PHP docs). Therefore, I added a check (see commit a58f40c) when escaping keywords, which generally is disabled, except for IDL PHP generator.
Also, when I replaced for-loops with substr_replace in createString and growByteBuffer, the performance improved, especially for longer strings. Below is a benchmark (here is the code).
Before the change:
BenchmarkCreateString/1 0.0019979476928711 ms
BenchmarkCreateString/10 0.0022983551025391 ms
BenchmarkCreateString/100 0.010838508605957 ms
BenchmarkCreateString/1000 0.083937644958496 ms
BenchmarkCreateString/10000 0.96836090087891 ms
BenchmarkCreateString/100000 8.6467790603638 ms
BenchmarkCreateString/1000000 82.010021209717 ms
BenchmarkCreateString/10000000 936.62708282471 ms
After the change:
BenchmarkCreateString/1 0.0019216537475586 ms
BenchmarkCreateString/10 0.0020408630371094 ms
BenchmarkCreateString/100 0.0075387954711914 ms
BenchmarkCreateString/1000 0.053601264953613 ms
BenchmarkCreateString/10000 0.52011966705322 ms
BenchmarkCreateString/100000 4.9904012680054 ms
BenchmarkCreateString/1000000 50.608458518982 ms
BenchmarkCreateString/10000000 506.61317825317 ms
This PR adds some missing functionality and improved performance to PHP flatbuffers:
During internal testing, I noticed that tables using PHP keywords as names (e.g., bytes, string) would yield errors in the generated code because keywords cannot be used as class names despite their casing (also mentioned in PHP docs). Therefore, I added a check (see commit a58f40c) when escaping keywords, which generally is disabled, except for IDL PHP generator.
Also, when I replaced for-loops with substr_replace in createString and growByteBuffer, the performance improved, especially for longer strings. Below is a benchmark (here is the code).
Before the change:
After the change: