microsoft / microsoft/STL

<algorithm>: algorithms should use TMP to provide optimized implementation for vector<bool> iterators

Open
#625 13 comments 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

performance
Dominant language
C++
Stars
11.1k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

MS's STL already uses metaprogramming to help the optimizer produce
optimized code. As an example, std::fill delegates to std::memset
if safe, which has the advantage of guaranteed good performance in
Debug mode, as well as not having to rely on the optimizer to salvage
reasonable ASM out of the actual code.

I would like optimizations like this to also happen when calling various
algorithms on std::vector<bool>, which currently does not happen.

As an example, this code

void clean_out(std::vector<bool>& vec) {
    std::fill(vec.begin(), vec.end(), false);
}

should end up calling memset, rather than doing whatever this is.

Other algorithms that could be optimized:

  • std::copy
  • std::count
  • std::find
  • std::equal
  • possibly others?

This would also improve the performance of std::vector<bool>'s member functions, as it internally uses std algorithms.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the std::fill example for std::vector iterators and compare its generated code with the linked Godbolt example. Review the proposed std::copy, std::count, std::find, and std::equal cases; done means determining and implementing suitable optimized paths, including the affected vector member functions.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.