Branch: refs/heads/smoke-me/khw-length
  Home:   https://github.com/Perl/perl5
  Commit: 2514820df30dbbefc8b1ebf924463bf4a5a92a41
      
https://github.com/Perl/perl5/commit/2514820df30dbbefc8b1ebf924463bf4a5a92a41
  Author: Karl Williamson <[email protected]>
  Date:   2020-11-16 (Mon, 16 Nov 2020)

  Changed paths:
    M ext/XS-APItest/APItest.pm
    M ext/XS-APItest/APItest.xs
    M ext/XS-APItest/t/utf8.t

  Log Message:
  -----------
  apitest


  Commit: c237ceb4c30b10781097155f5843bb235c2515e6
      
https://github.com/Perl/perl5/commit/c237ceb4c30b10781097155f5843bb235c2515e6
  Author: Karl Williamson <[email protected]>
  Date:   2020-11-16 (Mon, 16 Nov 2020)

  Changed paths:
    M Porting/bench.pl

  Log Message:
  -----------
  XXX don't push, khw customization for bench.pl


  Commit: fe868d5368726505a16cc3f9624996da395ad309
      
https://github.com/Perl/perl5/commit/fe868d5368726505a16cc3f9624996da395ad309
  Author: Karl Williamson <[email protected]>
  Date:   2020-11-16 (Mon, 16 Nov 2020)

  Changed paths:
    M ext/XS-APItest/t/utf8.t
    M inline.h
    M regcomp.c
    M utf8.c

  Log Message:
  -----------
  Use per-word calcs in utf8_length()

This commit changes utf8_length to read the input a word at a time.
The current method of looking per character is retained for shorter
strings.  The per-word method yields significant time savings for very
long strings and typical inputs.

The timings vary depending on the average number of bytes per character
in the input.  If all our characters were 13 bytes, this commit would
always be a loser, as we would be processing per 8 (or 4 on 32-bit
platforms) instead of 13.  But we don't care about performance for
non-Unicode code points, and the maximum legal Unicode code point
occupies 4 UTF-8 bytes, which means that is a wash on 32-bit platforms,
but a real gain on 64-bit ones.  And, except for emoji, most text in
modern languages is 3 byte max, with a significant amount of single byte
characters (e.g., for punctuation) even in non-Latin scripts.

For very long strings we would expect to use 1/8 the conditionals if the
input is entirely ASCII; 1/4 if entirely 2-byte UTF-8, and 1/2 if
entirely 4-byte.  (For 32-bit systems, the savings is approximately half
this.)  Because of set-up and tear-down complications these values are
limits that are approached the longer the string is (which is where it
matters most).

The per-word method kicks for input strings 96 bytes and longer.
There are complications, as it has to process per-byte to get to a word
boundary before reading per-word.  Here are benchmarks for a 2-byte word
using the best and worst case scenarios. (All benchmarks are for a
64-bit platform)

 Key:
     Ir   Instruction read
     Dr   Data read
     Dw   Data write
     COND conditional branches
     IND  indirect branches

The numbers represent raw counts per loop iteration.

Best:
string length 48 characters; 2 bytes per character;
0 bytes after word boundary

          nblead   npatch Ratio %
        -------- -------- -------
     Ir   1723.0   1873.0    92.0
     Dr    689.0    662.0   104.1
     Dw    288.0    333.0    86.5
   COND    219.0    192.0   114.1
    IND     36.0     36.0   100.0

Worst:
string length 48 characters; 2 bytes per character;
7 bytes after word boundary

          nblead   npatch Ratio %
        -------- -------- -------
     Ir   1750.0   1913.0    91.5
     Dr    700.0    675.0   103.7
     Dw    294.0    339.0    86.7
   COND    219.0    194.0   112.9
    IND     37.0     37.0   100.0


Compare: https://github.com/Perl/perl5/compare/2514820df30d%5E...fe868d536872

Reply via email to