On 3/30/22 11:20, Dumitru Ceara wrote:
> On 3/29/22 18:51, Rosemarie O'Riorden wrote:
>> To parse a json string prior to this change, json_lex_input is called
>> with each character of the string. If the character needs to be copied
>> to the buffer, it is copied individually. This is an expensive
>> operation, as often there are multiple characters in a row
>> that need to be copied, and copying memory in blocks is more efficient
>> than byte by byte. To improve this, the string is now copied
>> in blocks with an offset counter. A copy is performed when the parser
>> state equals done.
>>
>> Functions that are called for each character use a lot of CPU cycles.
>> Making these functions inline greatly reduces the cycles used and
>> improves overall performance. Since json_lex_input was only needed in
>> one place, it doesn't have to be its own function.
>>
>> There is also a conditional that checks if the current character is a
>> new line, which is quite unlikely. When this was examined with perf, the
>> comparison had a very high CPU cycle usage. To improve this, the
>> OVS_UNLIKELY macro was used, which forces the compiler to switch the
>> order of the instructions.
>>
>> Here is the improvement seen in the json-string-benchmark test:
>>
>>   SIZE      Q  S         BEFORE       AFTER      CHANGE
>> --------------------------------------------------------
>> 100000      0  0 :      0.842 ms     0.489 ms   -41.9 %
>> 100000      2  1 :      0.917 ms     0.535 ms   -41.7 %
>> 100000      10 1 :      1.063 ms     0.656 ms   -38.3 %
>> 10000000    0  0 :     85.328 ms    49.878 ms   -41.5 %
>> 10000000    2  1 :     92.555 ms    54.778 ms   -40.8 %
>> 10000000    10 1 :    106.728 ms    66.735 ms   -37.5 %
>> 100000000   0  0 :    955.375 ms   621.950 ms   -34.9 %
>> 100000000   2  1 :   1031.700 ms   665.200 ms   -35.5 %
>> 100000000   10 1 :   1189.300 ms   796.050 ms   -33.0 %
>>
>> Here Q is probability (%) for a character to be a '\"' and
>> S is probability (%) to be a special character ( < 32).
>>
>> Signed-off-by: Rosemarie O'Riorden <[email protected]>
>> ---
> 
> Hi Rosemarie,
> 
> I just have two small style related comments but I guess, if Ilya
> agrees, that those can be fixed up at commit time.  I should've
> mentioned those on the previous review but I missed them, sorry.
> 
> Aside from that the code looks OK to me, thanks!
> 
> Acked-by: Dumitru Ceara <[email protected]>

I removed the empty line, but I didn't move the function, because
it seems better to keep it close to the only place where it's
actually used, for better readability.

With that, applied.  Thanks!

Best regards, Ilya Maximets.
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to