public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/38132] New: std::string is faster with -D_GLIBCXX_DEBUG=1 than without
@ 2008-11-15 13:56 edwintorok at gmail dot com
2008-11-15 13:58 ` [Bug c++/38132] " edwintorok at gmail dot com
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: edwintorok at gmail dot com @ 2008-11-15 13:56 UTC (permalink / raw)
To: gcc-bugs
basic_string.tcc contains 'extern template basic_string<char>', which prevents
the template from being instantiated, and thus all calls to basic_string
methods remain calls even at -O3.
If I -D_GLIBCXX_DEBUG=1 _GLIBCXX_EXTERN_TEMPLATE is 0, thus it will no longer
contain 'extern template basic_string<char>', so the body of methods will be
available, and inlining will be performed.
However _GLIBCXX_DEBUG=1 activates debug code, so I would like to be able to
get the methods inlined w/o definining debug mode.
Can the semantics of 'extern template' be changed [*] in such a way, that *if*
the body of some of the methods are suitable for inlining, they will be inlined
(and other methods won't get instantiated), and if none of the methods are
suitable, the behaviour stays as currently.
[*] by introducing a new compiler flag, that can be activated at -O3 (and maybe
-O2) at the expense of code size.
--
Summary: std::string is faster with -D_GLIBCXX_DEBUG=1 than
without
Product: gcc
Version: 4.3.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: edwintorok at gmail dot com
GCC build triplet: x86_64-linux-gnu
GCC host triplet: x86_64-linux-gnu
GCC target triplet: x86_64-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38132
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/38132] std::string is faster with -D_GLIBCXX_DEBUG=1 than without
2008-11-15 13:56 [Bug c++/38132] New: std::string is faster with -D_GLIBCXX_DEBUG=1 than without edwintorok at gmail dot com
@ 2008-11-15 13:58 ` edwintorok at gmail dot com
2008-11-15 15:43 ` [Bug c++/38132] extern template prohibits inlining rguenth at gcc dot gnu dot org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: edwintorok at gmail dot com @ 2008-11-15 13:58 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from edwintorok at gmail dot com 2008-11-15 13:56 -------
Created an attachment (id=16682)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=16682&action=view)
example to illustrate
compile with g++ -O3, I get:
real 0m0.130s
user 0m0.100s
sys 0m0.028s
compile with g++ -D_GLIBCXX_DEBUG=1 -O3 I get:
real 0m0.080s
user 0m0.056s
sys 0m0.028s
If I explicitly instantiate the template, I get similar effect as of defining
_GLIBCXX_DEBUG:
template class basic_string<char>;
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38132
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/38132] extern template prohibits inlining
2008-11-15 13:56 [Bug c++/38132] New: std::string is faster with -D_GLIBCXX_DEBUG=1 than without edwintorok at gmail dot com
2008-11-15 13:58 ` [Bug c++/38132] " edwintorok at gmail dot com
@ 2008-11-15 15:43 ` rguenth at gcc dot gnu dot org
2009-04-16 22:10 ` pinskia at gcc dot gnu dot org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-11-15 15:43 UTC (permalink / raw)
To: gcc-bugs
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
Keywords| |missed-optimization
Summary|std::string is faster with -|extern template prohibits
|D_GLIBCXX_DEBUG=1 than |inlining
|without |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38132
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/38132] extern template prohibits inlining
2008-11-15 13:56 [Bug c++/38132] New: std::string is faster with -D_GLIBCXX_DEBUG=1 than without edwintorok at gmail dot com
2008-11-15 13:58 ` [Bug c++/38132] " edwintorok at gmail dot com
2008-11-15 15:43 ` [Bug c++/38132] extern template prohibits inlining rguenth at gcc dot gnu dot org
@ 2009-04-16 22:10 ` pinskia at gcc dot gnu dot org
2009-04-17 9:23 ` [Bug libstdc++/38132] basic_string.tcc methods not declared inline rguenth at gcc dot gnu dot org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-04-16 22:10 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from pinskia at gcc dot gnu dot org 2009-04-16 22:10 -------
Hmm, I think we need to implement extern template like C++0x says, I don't know
what it says about this point.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38132
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug libstdc++/38132] basic_string.tcc methods not declared inline
2008-11-15 13:56 [Bug c++/38132] New: std::string is faster with -D_GLIBCXX_DEBUG=1 than without edwintorok at gmail dot com
` (2 preceding siblings ...)
2009-04-16 22:10 ` pinskia at gcc dot gnu dot org
@ 2009-04-17 9:23 ` rguenth at gcc dot gnu dot org
2009-04-17 10:12 ` paolo dot carlini at oracle dot com
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-04-17 9:23 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from rguenth at gcc dot gnu dot org 2009-04-17 09:23 -------
We had this for a short time but then see
2009-02-24 Richard Guenther <rguenther@suse.de>
PR c++/39242
* pt.c (instantiate_decl): Do not instantiate extern, non-inline
declared functions.
thus, if the functions would be marked inline we should still instantiate them
(otherwise we run into standard conformance issues like in that PR).
I also seem to remember that we hide implementation details of these functions
to be able to change them without breaking the ABI. But Paolo likely knows
more.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|c++ |libstdc++
Summary|extern template prohibits |basic_string.tcc methods not
|inlining |declared inline
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38132
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug libstdc++/38132] basic_string.tcc methods not declared inline
2008-11-15 13:56 [Bug c++/38132] New: std::string is faster with -D_GLIBCXX_DEBUG=1 than without edwintorok at gmail dot com
` (3 preceding siblings ...)
2009-04-17 9:23 ` [Bug libstdc++/38132] basic_string.tcc methods not declared inline rguenth at gcc dot gnu dot org
@ 2009-04-17 10:12 ` paolo dot carlini at oracle dot com
2009-04-17 10:28 ` paolo dot carlini at oracle dot com
2009-04-17 10:50 ` rguenth at gcc dot gnu dot org
6 siblings, 0 replies; 8+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-04-17 10:12 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from paolo dot carlini at oracle dot com 2009-04-17 10:12 -------
Frankly, I don't think this is an issue. What we really want, is that all
inline functions get inlined anyway, debug mode or not, and this is correctly
happening, as far as I can see. Out of line functions are expected to not be
inlined, even at -O3, because of the extern templates, indeed. All in all, also
considering other metrics, like compile-time performance, code-size, and the
ABI-impact of anything having to do with strings, I don't believe this is going
to change any time soon. To repeat, the maintainers are well aware that, due to
extern inline, out of line functions are not inlined even at -O3, but that is
believed to be a good compromise, in general, outside the case of some special
micro-benchmarks. It's definitely a well known design choice, which existed for
string since the very beginning of the project.
For this specific micro-benchmark, the performance difference in debug-mode is
noticeable only in 4.3.x, it wasn't in 4.2.x, probably because we are now
inlining large functions a bit more easily. Actually the suppression of extern
inline in debug-mode is just an historical accident, necessary in order to make
sure debug-mode works also for the very special case of strings (vs all the
standard containers). Some maintainers argued at length *against* it, because
indeed it's sort of an hack, you can find something in the archive about it.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38132
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug libstdc++/38132] basic_string.tcc methods not declared inline
2008-11-15 13:56 [Bug c++/38132] New: std::string is faster with -D_GLIBCXX_DEBUG=1 than without edwintorok at gmail dot com
` (4 preceding siblings ...)
2009-04-17 10:12 ` paolo dot carlini at oracle dot com
@ 2009-04-17 10:28 ` paolo dot carlini at oracle dot com
2009-04-17 10:50 ` rguenth at gcc dot gnu dot org
6 siblings, 0 replies; 8+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-04-17 10:28 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from paolo dot carlini at oracle dot com 2009-04-17 10:27 -------
Of course s/extern inline/extern template
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38132
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug libstdc++/38132] basic_string.tcc methods not declared inline
2008-11-15 13:56 [Bug c++/38132] New: std::string is faster with -D_GLIBCXX_DEBUG=1 than without edwintorok at gmail dot com
` (5 preceding siblings ...)
2009-04-17 10:28 ` paolo dot carlini at oracle dot com
@ 2009-04-17 10:50 ` rguenth at gcc dot gnu dot org
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-04-17 10:50 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from rguenth at gcc dot gnu dot org 2009-04-17 10:50 -------
Thus, wontfix.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |WONTFIX
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38132
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2009-04-17 10:50 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-15 13:56 [Bug c++/38132] New: std::string is faster with -D_GLIBCXX_DEBUG=1 than without edwintorok at gmail dot com
2008-11-15 13:58 ` [Bug c++/38132] " edwintorok at gmail dot com
2008-11-15 15:43 ` [Bug c++/38132] extern template prohibits inlining rguenth at gcc dot gnu dot org
2009-04-16 22:10 ` pinskia at gcc dot gnu dot org
2009-04-17 9:23 ` [Bug libstdc++/38132] basic_string.tcc methods not declared inline rguenth at gcc dot gnu dot org
2009-04-17 10:12 ` paolo dot carlini at oracle dot com
2009-04-17 10:28 ` paolo dot carlini at oracle dot com
2009-04-17 10:50 ` rguenth at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).