Skip to content
  • Knut Anders Hatlen's avatar
    8d10f2ff
    Bug#30472888: IMPROVE THE PERFORMANCE OF INTEGER HANDLING IN THE TEXT PROTOCOL · 8d10f2ff
    Knut Anders Hatlen authored
    When retrieving large result sets containing many integers from a
    secondary engine, conversion of the integers to strings for sending
    over the text protocol is a bottleneck.
    
    This patch improves the performance of some functions that are used by
    the text protocol for converting integers, and also the integer
    components of temporal values, to strings.
    
    Protocol_text::store_{tiny,short,long,longlong,date,time,datetime}():
    
    - Write the string value directly into the protocol buffer, instead of
      writing it to a stack buffer first and copying it to the protocol
      buffer.
    
    int10_to_str(), longlong10_to_str():
    
    - Write the string value directly into the destination buffer, instead
      of writing it to a stack buffer first and copying it to the
      destination buffer.
    
    - Write two digits at a time, to reduce the number of relatively
      expensive modulo and division by 10 operations.
    
    int2str():
    
    - Removed. It had only one caller, which was updated to use
      longlong2str() instead.
    
    longlong2str():
    
    - Remove an optimization for VAX, which had a negative impact on the
      performance on modern hardware.
    
    - Change some callers which requested conversion with base 10 to use
      longlong10_to_str() instead. longlong10_to_str() is specialized for
      base 10, and is faster than the generic variant.
    
    my_date_to_str(), my_time_to_str(), my_datetime_to_str():
    
    - Use the helper functions written for int10_to_str() and
      longlong10_to_str() instead of the similar helper functions in
      my_time.cc, and remove the helper functions in my_time.cc.
    
    Microbenchmarks (64-bit, Intel Core i7-4770 3.4 GHz, GCC 8.3.0):
    
    BM_longlong10_to_str                  34 ns/iter ->  16 ns/iter
    BM_longlong2str                      140 ns/iter -> 106 ns/iter
    BM_my_time_to_str                     23 ns/iter ->   9 ns/iter
    BM_my_date_to_str                      6 ns/iter ->   3 ns/iter
    BM_my_datetime_to_str                 26 ns/iter ->  10 ns/iter
    BM_Protocol_text_store_tiny           11 ns/iter ->   8 ns/iter
    BM_Protocol_text_store_longlong       37 ns/iter ->  18 ns/iter
    BM_Protocol_text_store_date           12 ns/iter ->   6 ns/iter
    BM_Protocol_text_store_time           27 ns/iter ->  13 ns/iter
    BM_Protocol_text_store_datetime       30 ns/iter ->  13 ns/iter
    
    Change-Id: I4e758e4ab9a218e02ed28da8dd3bdabe675fbfd6
    8d10f2ff
    Bug#30472888: IMPROVE THE PERFORMANCE OF INTEGER HANDLING IN THE TEXT PROTOCOL
    Knut Anders Hatlen authored
    When retrieving large result sets containing many integers from a
    secondary engine, conversion of the integers to strings for sending
    over the text protocol is a bottleneck.
    
    This patch improves the performance of some functions that are used by
    the text protocol for converting integers, and also the integer
    components of temporal values, to strings.
    
    Protocol_text::store_{tiny,short,long,longlong,date,time,datetime}():
    
    - Write the string value directly into the protocol buffer, instead of
      writing it to a stack buffer first and copying it to the protocol
      buffer.
    
    int10_to_str(), longlong10_to_str():
    
    - Write the string value directly into the destination buffer, instead
      of writing it to a stack buffer first and copying it to the
      destination buffer.
    
    - Write two digits at a time, to reduce the number of relatively
      expensive modulo and division by 10 operations.
    
    int2str():
    
    - Removed. It had only one caller, which was updated to use
      longlong2str() instead.
    
    longlong2str():
    
    - Remove an optimization for VAX, which had a negative impact on the
      performance on modern hardware.
    
    - Change some callers which requested conversion with base 10 to use
      longlong10_to_str() instead. longlong10_to_str() is specialized for
      base 10, and is faster than the generic variant.
    
    my_date_to_str(), my_time_to_str(), my_datetime_to_str():
    
    - Use the helper functions written for int10_to_str() and
      longlong10_to_str() instead of the similar helper functions in
      my_time.cc, and remove the helper functions in my_time.cc.
    
    Microbenchmarks (64-bit, Intel Core i7-4770 3.4 GHz, GCC 8.3.0):
    
    BM_longlong10_to_str                  34 ns/iter ->  16 ns/iter
    BM_longlong2str                      140 ns/iter -> 106 ns/iter
    BM_my_time_to_str                     23 ns/iter ->   9 ns/iter
    BM_my_date_to_str                      6 ns/iter ->   3 ns/iter
    BM_my_datetime_to_str                 26 ns/iter ->  10 ns/iter
    BM_Protocol_text_store_tiny           11 ns/iter ->   8 ns/iter
    BM_Protocol_text_store_longlong       37 ns/iter ->  18 ns/iter
    BM_Protocol_text_store_date           12 ns/iter ->   6 ns/iter
    BM_Protocol_text_store_time           27 ns/iter ->  13 ns/iter
    BM_Protocol_text_store_datetime       30 ns/iter ->  13 ns/iter
    
    Change-Id: I4e758e4ab9a218e02ed28da8dd3bdabe675fbfd6
Loading