https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80826

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I don't know why it's so slow, or if it's possible to change the libstdc++ code
to help the c++98 case (I doubt it).

But it helps a lot if you insert the correct type:

    mMap.insert (std::pair<const std::string, int>("1", 1));

The value_type of map<K, T> is pair<const K, T> not pair<K, T>. Inserting the
wrong type means the compiler instantiates two different specializations of
std::pair and has to convert from one to the other.

With -O1 the time-report for that is:
 TOTAL      : 348.27         2.37       351.29        1595960 kB

That's still slow, but not "making the box unusable" slow.

It helps a bit more if you create an array of pairs and insert from that:

    std::pair<const std::string, int> pairs[] = {
        std::pair<const std::string, int>("1", 1),
        ...
    };

    int n = sizeof(pairs)/sizeof(pairs[0]);
    std::map<std::string, int> mMap(pairs, pairs + n);

With -O1 the time-report for that is:
 TOTAL      : 178.28         1.66       180.50        1071340 kB


Both runs print:

m.cc:6:5: note: variable tracking size limit exceeded with
-fvar-tracking-assignments, retrying without

Reply via email to