ruby / json

JSON implementation for Ruby
https://ruby.github.io/json
Other
673 stars 326 forks source link

Optimize `fbuffer_inc_capa` #597

Closed casperisfine closed 5 days ago

casperisfine commented 1 month ago

On my JSON.dump benchmark it shows up as 6% of runtime, compared to 40% for convert_UTF8_to_JSON.

Capture d’écran 2024-09-02 à 13 48 22

Since the vast majority of the time this function is called we still have some buffer capacity, we might as well check that first and skip the expensive loop etc.

With this change my profiler now report this function as 0.7%, so almost 10x better.

Capture d’écran 2024-09-02 à 13 48 34