[Patch] [BZ 15884] strcoll: improve performance by removing the cache

Leonhard Holz leonhard.holz@web.de
Mon Oct 13 12:20:00 GMT 2014


Hi Siddhesh,

please have a look at the attached JSON output of the strcoll benchmark.

Best,
Leonhard

Am 08.10.2014 11:09, schrieb Siddhesh Poyarekar:
> On Wed, Oct 08, 2014 at 10:32:40AM +0200, Leonhard Holz wrote:
>> Defensive programming... the input files are all generated and might be
>> regenerated by some else in the future.
>
> Fair enough.
>
>> Is this really an issue? It's only four times the size of a pointer, the
>> benchmark is not affected by it and the malloc's will not make the
>> code nicer.
>
> It does make the code better in addition to the fact that it is more
> familiar coding style; I've elaborated on the 'how' below.  In general
> the number of copies of the struct in all those functions is just
> wasteful.  It may not affect the benchmark, but that's no reason to
> keep it sloppy.
>
>> The idea is to set a fallback locale at the beginning which is used if one
>> of the benchmarked locales are not available. This is why the used locale is
>> also printed in the results. So you want it to skip the run if the needed
>> locale is not available?
>
> The test should fail with an error, because the locale should always
> be available in this test - we're generating them.  In fact, I think
> we might need to wire things up so that locales are generated during
> `make bench`.  I don't think that's happening currently because
> they're currently generated as part of `make check`.
>
>>>>    char *text = read_file (filename);
>>>>    word_list list = tokenize_string (text, delim);
>>>>
>>>>    word_list *tests = malloc (INNER_LOOP_ITERS * sizeof (word_list));
>>>>    for (i = 0; i < INNER_LOOP_ITERS; i++)
>>>>      tests[i] = copy_word_list (list);
>>>
>>> This will obviously have to be adjusted (and hence made cleaner) once
>>> copy_word_list and all other functions above pass pointers to
>>> word_list.
>>
>> Maybe I'll see when I change it but maybe you can give me a hint what you
>> mean with "cleaner".
>
> Your word_list API (for the lack of a better term) becomes cleaner:
>
> 1. tokenize_string should allocate and returns a word_list.  You can
>     rename it to new_word_list to make it more consistent
> 2. copy_word_list allocates (and copies) and returns a word_list
> 3. free_word_list frees the word_list
>
> Everything else just uses the reference and can hence modify the list
> in place.  sort_word_list for example would no longer need to create a
> copy of the passed in object.  Oh, and it looks like sort_word_list is
> unused, so you can just remove it.
>
>> Is there some code that can be reused for output in JSON format?
>
> See bench-skeleton.c for an example.  Or maybe the malloc benchmark
> patch that Will Newton posted recently[1].
>
> Siddhesh
>
> [1] http://patchwork.sourceware.org/patch/3092/
>
-------------- next part --------------
  "strcoll": {
   "file list": {
    "directory": "..",
    "file_count": 39086,
    "locale": "en_US.UTF-8",
    "duration": 4.72532e+09,
    "iterations": 16,
    "mean": 2.95333e+08
   },
   "word list": {
    "file": "strcoll-inputs/lorem_ipsum_vi_VN",
    "locale": "vi_VN.UTF-8",
    "duration": 4,86973e+07,
    "iterations": 16,
    "mean": 3,04358e+06
   },
   "word list": {
    "file": "strcoll-inputs/lorem_ipsum_en_US",
    "locale": "en_US.UTF-8",
    "duration": 4.39686e+07,
    "iterations": 16,
    "mean": 2.74804e+06
   },
   "word list": {
    "file": "strcoll-inputs/lorem_ipsum_ar_SA",
    "locale": "ar_SA.UTF-8",
    "duration": 5.45405e+07,
    "iterations": 16,
    "mean": 3.40878e+06
   },
   "word list": {
    "file": "strcoll-inputs/lorem_ipsum_en_US",
    "locale": "en_US.UTF-8",
    "duration": 4.63733e+07,
    "iterations": 16,
    "mean": 2.89833e+06
   },
   "word list": {
    "file": "strcoll-inputs/lorem_ipsum_zh_CN",
    "locale": "zh_CN.UTF-8",
    "duration": 2.09213e+07,
    "iterations": 16,
    "mean": 1.30758e+06
   },
   "word list": {
    "file": "strcoll-inputs/lorem_ipsum_cs_CZ",
    "locale": "cs_CZ.UTF-8",
    "duration": 5,6144e+07,
    "iterations": 16,
    "mean": 3,509e+06
   },
   "word list": {
    "file": "strcoll-inputs/lorem_ipsum_en_GB",
    "locale": "en_GB.UTF-8",
    "duration": 5.56252e+07,
    "iterations": 16,
    "mean": 3.47658e+06
   },
   "word list": {
    "file": "strcoll-inputs/lorem_ipsum_da_DK",
    "locale": "da_DK.UTF-8",
    "duration": 4,97187e+07,
    "iterations": 16,
    "mean": 3,10742e+06
   },
   "word list": {
    "file": "strcoll-inputs/lorem_ipsum_pl_PL",
    "locale": "pl_PL.UTF-8",
    "duration": 4,46531e+07,
    "iterations": 16,
    "mean": 2,79082e+06
   },
   "word list": {
    "file": "strcoll-inputs/lorem_ipsum_fr_FR",
    "locale": "fr_FR.UTF-8",
    "duration": 5,47468e+07,
    "iterations": 16,
    "mean": 3,42168e+06
   },
   "word list": {
    "file": "strcoll-inputs/lorem_ipsum_pt_PT",
    "locale": "pt_PT.UTF-8",
    "duration": 5,45736e+07,
    "iterations": 16,
    "mean": 3,41085e+06
   },
   "word list": {
    "file": "strcoll-inputs/lorem_ipsum_el_GR",
    "locale": "el_GR.UTF-8",
    "duration": 7,71665e+07,
    "iterations": 16,
    "mean": 4,8229e+06
   },
   "word list": {
    "file": "strcoll-inputs/lorem_ipsum_ru_RU",
    "locale": "ru_RU.UTF-8",
    "duration": 5,48712e+07,
    "iterations": 16,
    "mean": 3,42945e+06
   },
   "word list": {
    "file": "strcoll-inputs/lorem_ipsum_iw_IL",
    "locale": "iw_IL.UTF-8",
    "duration": 5.38097e+07,
    "iterations": 16,
    "mean": 3.3631e+06
   },
   "word list": {
    "file": "strcoll-inputs/lorem_ipsum_es_ES",
    "locale": "es_ES.UTF-8",
    "duration": 5,28691e+07,
    "iterations": 16,
    "mean": 3,30432e+06
   },
   "word list": {
    "file": "strcoll-inputs/lorem_ipsum_hi_IN",
    "locale": "hi_IN.UTF-8",
    "duration": 3.64249e+09,
    "iterations": 16,
    "mean": 2.27656e+08
   },
   "word list": {
    "file": "strcoll-inputs/lorem_ipsum_sv_SE",
    "locale": "sv_SE.UTF-8",
    "duration": 4,69127e+07,
    "iterations": 16,
    "mean": 2,93204e+06
   },
   "word list": {
    "file": "strcoll-inputs/lorem_ipsum_hu_HU",
    "locale": "hu_HU.UTF-8",
    "duration": 7,46276e+07,
    "iterations": 16,
    "mean": 4,66422e+06
   },
   "word list": {
    "file": "strcoll-inputs/lorem_ipsum_tr_TR",
    "locale": "tr_TR.UTF-8",
    "duration": 4,89509e+07,
    "iterations": 16,
    "mean": 3,05943e+06
   },
   "word list": {
    "file": "strcoll-inputs/lorem_ipsum_is_IS",
    "locale": "is_IS.UTF-8",
    "duration": 4,36657e+07,
    "iterations": 16,
    "mean": 2,72911e+06
   },
   "word list": {
    "file": "strcoll-inputs/lorem_ipsum_it_IT",
    "locale": "it_IT.UTF-8",
    "duration": 5,59324e+07,
    "iterations": 16,
    "mean": 3,49578e+06
   },
   "word list": {
    "file": "strcoll-inputs/lorem_ipsum_sr_RS",
    "locale": "sr_RS.UTF-8",
    "duration": 5,25292e+07,
    "iterations": 16,
    "mean": 3,28307e+06
   },
   "word list": {
    "file": "strcoll-inputs/lorem_ipsum_ja_JP",
    "locale": "ja_JP.UTF-8",
    "duration": 1.96942e+07,
    "iterations": 16,
    "mean": 1.23089e+06
   }
  }


More information about the Libc-alpha mailing list