<div dir="auto"><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Jan 1, 2017 11:55 AM, "Vladislav Egorov" <<a href="mailto:vegorov180@gmail.com">vegorov180@gmail.com</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
01.01.2017 06:41, Kenneth Graunke пишет:<div class="elided-text"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Sunday, January 1, 2017 1:34:27 AM PST Marek Olšák wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
From: Marek Olšák <<a href="mailto:marek.olsak@amd.com" target="_blank">marek.olsak@amd.com</a>><br>
<br>
This reduces compile times by 4.5% with the Gallium noop driver and<br>
gl_constants::GLSLOptimizeCons<wbr>ervatively == true.<br>
</blockquote>
Compile times of...what exactly? Do you have any statistics for this<br>
by itself?<br>
<br>
Assuming we add your helper, this patch looks reasonable.<br>
Reviewed-by: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org" target="_blank">kenneth@whitecape.org</a>><br>
<br>
BTW, I suspect you could get some additional speed up by changing<br>
<br>
parser->output = ralloc_strdup(parser, "");<br>
<br>
to something like:<br>
<br>
parser->output = ralloc_size(parser, strlen(orig_concatenated_src))<wbr>;<br>
parser->output[0] = '\0';<br>
<br>
to try and avoid reallocations. rewrite_tail will realloc just enough<br>
space every time it allocates, which means once you reallocate, you're<br>
going to be calling realloc on every single token. Yuck!<br>
<br>
ralloc/talloc's string libraries were never meant for serious string<br>
processing like the preprocessor does. They're meant for convenience<br>
when constructing debug messages which don't need to be that efficient.<br>
<br>
Perhaps a better approach would be to have the preprocessor do this<br>
itself. Just ralloc_size() output and initialize the null byte.<br>
reralloc to double the size if you need more space. At the end of<br>
preprocessing, reralloc to output_length at the end of free any waste<br>
from doubling.<br>
<br>
I suspect that would be a *lot* more efficient, and is probably what<br>
we should have done in the first place...<br>
</blockquote></div>
I have similar patch (maybe need 1-2 days to clean it up), and I've tested both variants. String in exponentially growing (by +50%) string buffer works better, but not *THAT* much better as I expected. It seems that in the sequence of str = realloc(str, 1001); str = realloc(str, 1002); str = realloc(str, 1003), etc. most of reallocs will be non-moving in both glibc's allocator and jemalloc. For example, jemalloc have size classes that already grow exponentially by 15-25% - ..., 4K, 5K, 6K, 7K, 8K, 10K, 12K, 14K, 16K, 20K, 24K, .., 4M, 5M, ... realloc will just test if the requested size belongs to the same size class and do nothing. Reallocs inside of the same size class will be always non-moving and almost free. Overall avoiding formatted printing (DOUBLE formatted printing, which is entirely avoidable too) gives the single largest boost to the pre-processor.<br>
<br>
Benchmark on my shader-db (glcpp and shader-db's run smashed together to do only preprocessing). Note that I used old jemalloc from Ubuntu 16.04, which can be important, because jemalloc changed its size class strategy since then.<br>
perf stat --repeat 10<br>
master 8.91s<br>
master+jemalloc 8.60s<br>
Marek's patch 5.50s<br>
Marek's patch+jemalloc 5.03s<br>
my string_buffer 4.57s<br>
my string_buffer+jemalloc 4.43s<br>
my series 3.83s<br>
my series+jemalloc 3.68s<br></blockquote></div></div></div><div dir="auto"><br></div><div dir="auto">Since you are further than me, let's merge your work instead.</div><div dir="auto"><br></div><div dir="auto">Marek</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</blockquote></div><br></div></div></div>