On Sun, Jul 27, 2025 at 2:42 PM Luc Grosheintz <[email protected]>
wrote:
> This is a sequence of related improvements to <mdspan> we
> discussed during review and then postponed. The ideas are:
>
> * Pre-compute the product of static extents; and a follow up
> for fine-tuning for low-rank extents.
>
> * Returning to extents::operator== to improve the case of mixed
> dynamic/static extents, revealed that this can be simplified
> quite a bit.
>
> * There's several templates that depend on the IndexType, but
> the actual code only needs the static extents. Therefore,
> extents with the same Indices... but different IndexType can
> use the same code.
>
> * Recently, libstdc++ code was refactored to avoid
> numeric_limits and use __int_traits instead. Unfortunately,
> this is currently completely ineffective for <mdspan>. But
> since, it's a good idea, the changes are ready, and it might
> anyway be needed in the future, I've submitted the patch
> regardless.
>
> Many of these look like optimizations, but since I've not
> performed any runtime experiments, it might not be fair to call
> them such. However, because they're principled changes to the
> source code and the generated code "looks faster" (though it
> might be overly bold to claim that I could tell), I think it
> makes sense to propose them regardless.
>
> Therefore, if anything looks iffy or you feel one should be
> measuring performance, please suggest that we start.
>
There is nothing looking iffy in the test, but with the introduction of
precomputed
indices, we are introducing some code size/runtime tradeoff, and I think
doing some
microbenchmark before/after would be valuable. I think something really
small like
just having GoogleBenchmark that invokes the stride on various combinations
of
static/dynamic indexes would be sufficient.
>
> The commit messages are a lot longer than in the past, because
> the justification for each change is included, please let me know
> if I should shorten them.
>
I found the information presented in the commit messages relevant and
interesting,
so I will keep them.
>
> Luc Grosheintz (6):
> libstdc++: Fix style issues in <mdspan>.
> libstdc++: Precompute products of static extents.
> libstdc++: Improve low-rank layout_{left,right}::stride.
> libstdc++: Improve extents::operator==.
> libstdc++: Reduce template instantiations in <mdspan>.
> libstdc++: Replace numeric_limit with __int_traits in mdspan.
>
> libstdc++-v3/include/std/mdspan | 195 +++++++++++-------
> .../mdspan/extents/class_mandates_neg.cc | 3 +
> 2 files changed, 128 insertions(+), 70 deletions(-)
>
> --
> 2.50.0
>
>