[ 
https://issues.apache.org/jira/browse/STDCXX-914?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12594770#action_12594770
 ] 

sebor edited comment on STDCXX-914 at 11/8/08 4:16 PM:
--------------------------------------------------------------

gprof flat profile for a 15D build with gcc 4.3.0 on x86_64 (with most template 
arguments removed for brevity):
\\
{noformat}
Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  ns/call  ns/call  name    
 33.40      0.08     0.08  1000000    80.15   200.37  std::string 
lex_cast<std::string, long>(long const&)
 16.70      0.12     0.04  1000000    40.07    90.17  
std::stringstream::~stringstream()
 16.70      0.16     0.04                             main
 12.52      0.19     0.03  1000000    30.06    40.07  std::iostream::~iostream()
  8.35      0.21     0.02  1000000    20.04    20.04  
std::iostream::iostream(std::streambuf*)
  4.17      0.22     0.01  1000000    10.02    10.02  std::ostream::~ostream()
  4.17      0.23     0.01  1000000    10.02    30.06  
std::stringstream::stringstream(__rw::__rw_openmode)
  4.17      0.24     0.01  1000000    10.02    10.02  std::ios::~ios()
  0.00      0.24     0.00 14000002     0.00     0.00  data_start
  0.00      0.24     0.00  1000001     0.00     0.00  
std::allocator<char>::allocator()
  0.00      0.24     0.00  1000000     0.00     0.00  
__rw::__string_ref::~__string_ref()
  0.00      0.24     0.00  1000000     0.00     0.00  
std::stringstream::rdbuf() const
  0.00      0.24     0.00  1000000     0.00     0.00  std::istream::~istream()
{noformat}

gprof call graph:
{noformat}
granularity: each sample hit covers 2 byte(s) for 4.16% of 0.24 seconds

index % time    self  children    called     name
                                                 <spontaneous>
[1]    100.0    0.04    0.20                 main [1]
                0.08    0.12 1000000/1000000     std::string 
lex_cast<std::string, long>(long const&) [2]
                0.00    0.00 3000002/14000002     data_start [9]
                0.00    0.00       1/1000001     
std::allocator<char>::allocator() [15]
-----------------------------------------------
                0.08    0.12 1000000/1000000     main [1]
[2]     83.3    0.08    0.12 1000000         std::string lex_cast<std::string, 
long>(long const&) [2]
                0.04    0.05 1000000/1000000     
std::stringstream::~stringstream() [3]
                0.01    0.02 1000000/1000000     
std::stringstream::stringstream(__rw::__rw_openmode) [5]
                0.00    0.00 5000000/14000002     data_start [9]
                0.00    0.00 1000000/1000001     
std::allocator<char>::allocator() [15]
-----------------------------------------------
                0.04    0.05 1000000/1000000     std::string 
lex_cast<std::string, long>(long const&) [2]
[3]     37.5    0.04    0.05 1000000         std::stringstream::~stringstream() 
[3]
                0.03    0.01 1000000/1000000     std::iostream::~iostream() [4]
                0.01    0.00 1000000/1000000     std::ios::~ios() [8]
                0.00    0.00 1000000/14000002     data_start [9]
-----------------------------------------------
                0.03    0.01 1000000/1000000     
std::stringstream::~stringstream() [3]
[4]     16.7    0.03    0.01 1000000         std::iostream::~iostream() [4]
                0.01    0.00 1000000/1000000     std::ostream::~ostream() [7]
                0.00    0.00 1000000/1000000     std::istream::~istream() [18]
-----------------------------------------------
                0.01    0.02 1000000/1000000     std::string 
lex_cast<std::string, long>(long const&) [2]
[5]     12.5    0.01    0.02 1000000         
std::stringstream::stringstream(__rw::__rw_openmode) [5]
                0.02    0.00 1000000/1000000     
std::iostream::iostream(std::streambuf*) [6]
                0.00    0.00 2000000/14000002     data_start [9]
                0.00    0.00 1000000/1000000     std::stringstream::rdbuf() 
const [17]
-----------------------------------------------
                0.02    0.00 1000000/1000000     
std::stringstream::stringstream(__rw::__rw_openmode) [5]
[6]      8.3    0.02    0.00 1000000         
std::iostream::iostream(std::streambuf*) [6]
                0.00    0.00 2000000/14000002     data_start [9]
-----------------------------------------------
                0.01    0.00 1000000/1000000     std::iostream::~iostream() [4]
[7]      4.2    0.01    0.00 1000000         std::ostream::~ostream() [7]
-----------------------------------------------
                0.01    0.00 1000000/1000000     
std::stringstream::~stringstream() [3]
[8]      4.2    0.01    0.00 1000000         std::ios::~ios() [8]
                0.00    0.00 1000000/14000002     data_start [9]
-----------------------------------------------
                0.00    0.00 1000000/14000002     std::ios::~ios() [8]
                0.00    0.00 1000000/14000002     
std::stringstream::~stringstream() [3]
                0.00    0.00 2000000/14000002     
std::iostream::iostream(std::streambuf*) [6]
                0.00    0.00 2000000/14000002     
std::stringstream::stringstream(__rw::__rw_openmode) [5]
                0.00    0.00 3000002/14000002     main [1]
                0.00    0.00 5000000/14000002     std::string 
lex_cast<std::string, long>(long const&) [2]
[9]      0.0    0.00    0.00 14000002         data_start [9]
-----------------------------------------------
                0.00    0.00       1/1000001     main [1]
                0.00    0.00 1000000/1000001     std::string 
lex_cast<std::string, long>(long const&) [2]
[15]     0.0    0.00    0.00 1000001         std::allocator<char>::allocator() 
[15]
-----------------------------------------------
                0.00    0.00 1000000/1000000     
std::allocator<__rw::__string_ref>::destroy(__rw::__string_ref*) [19]
[16]     0.0    0.00    0.00 1000000         
__rw::__string_ref::~__string_ref() [16]
-----------------------------------------------
                0.00    0.00 1000000/1000000     
std::stringstream::stringstream(__rw::__rw_openmode) [5]
[17]     0.0    0.00    0.00 1000000         std::stringstream::rdbuf() const 
[17]
-----------------------------------------------
                0.00    0.00 1000000/1000000     std::iostream::~iostream() [4]
[18]     0.0    0.00    0.00 1000000         std::istream::~istream() [18]
-----------------------------------------------
{noformat}
and index by function name:
{noformat}
   [2] std::string lex_cast<std::string, long>(long const&)
   [4] std::iostream::~iostream()
   [8] std::ios::~ios()
  [16] __rw::__string_ref::~__string_ref()
  [18] std::istream::~istream()
   [9] data_start
  [17] std::stringstream::rdbuf() const
   [7] std::ostream::~ostream()
   [1] main
  [15] std::allocator<char>::allocator()
   [5] std::stringstream::stringstream(__rw::__rw_openmode)
   [6] std::iostream::iostream(std::streambuf*)
   [3] std::stringstream::~stringstream()
{noformat}

      was (Author: sebor):
    gprof flat profile for a 15D build with gcc 4.3.0 on x86_64:
\\
{noformat}
Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  ns/call  ns/call  name    
 33.40      0.08     0.08  1000000    80.15   200.37  std::string 
lex_cast<std::string, long>(long const&)
 16.70      0.12     0.04  1000000    40.07    90.17  
std::stringstream::~stringstream()
 16.70      0.16     0.04                             main
 12.52      0.19     0.03  1000000    30.06    40.07  std::iostream::~iostream()
  8.35      0.21     0.02  1000000    20.04    20.04  
std::iostream::iostream(std::streambuf*)
  4.17      0.22     0.01  1000000    10.02    10.02  std::ostream::~ostream()
  4.17      0.23     0.01  1000000    10.02    30.06  
std::stringstream::stringstream(__rw::__rw_openmode)
  4.17      0.24     0.01  1000000    10.02    10.02  std::ios::~ios()
  0.00      0.24     0.00 14000002     0.00     0.00  data_start
  0.00      0.24     0.00  1000001     0.00     0.00  
std::allocator<char>::allocator()
  0.00      0.24     0.00  1000000     0.00     0.00  __rw::__string_ref<char, 
std::char_traits<char>, std::allocator<char> >::~__string_ref()
  0.00      0.24     0.00  1000000     0.00     0.00  
std::stringstream::rdbuf() const
  0.00      0.24     0.00  1000000     0.00     0.00  std::istream::~istream()
{noformat}

gprof call graph:
{noformat}
granularity: each sample hit covers 2 byte(s) for 4.16% of 0.24 seconds

index % time    self  children    called     name
                                                 <spontaneous>
[1]    100.0    0.04    0.20                 main [1]
                0.08    0.12 1000000/1000000     std::string 
lex_cast<std::string, long>(long const&) [2]
                0.00    0.00 3000002/14000002     data_start [9]
                0.00    0.00       1/1000001     
std::allocator<char>::allocator() [15]
-----------------------------------------------
                0.08    0.12 1000000/1000000     main [1]
[2]     83.3    0.08    0.12 1000000         std::string lex_cast<std::string, 
long>(long const&) [2]
                0.04    0.05 1000000/1000000     
std::stringstream::~stringstream() [3]
                0.01    0.02 1000000/1000000     
std::stringstream::stringstream(__rw::__rw_openmode) [5]
                0.00    0.00 5000000/14000002     data_start [9]
                0.00    0.00 1000000/1000001     
std::allocator<char>::allocator() [15]
-----------------------------------------------
                0.04    0.05 1000000/1000000     std::string 
lex_cast<std::string, long>(long const&) [2]
[3]     37.5    0.04    0.05 1000000         std::stringstream::~stringstream() 
[3]
                0.03    0.01 1000000/1000000     std::iostream::~iostream() [4]
                0.01    0.00 1000000/1000000     std::ios::~ios() [8]
                0.00    0.00 1000000/14000002     data_start [9]
-----------------------------------------------
                0.03    0.01 1000000/1000000     
std::stringstream::~stringstream() [3]
[4]     16.7    0.03    0.01 1000000         std::iostream::~iostream() [4]
                0.01    0.00 1000000/1000000     std::ostream::~ostream() [7]
                0.00    0.00 1000000/1000000     std::istream::~istream() [18]
-----------------------------------------------
                0.01    0.02 1000000/1000000     std::string 
lex_cast<std::string, long>(long const&) [2]
[5]     12.5    0.01    0.02 1000000         
std::stringstream::stringstream(__rw::__rw_openmode) [5]
                0.02    0.00 1000000/1000000     
std::iostream::iostream(std::streambuf*) [6]
                0.00    0.00 2000000/14000002     data_start [9]
                0.00    0.00 1000000/1000000     std::stringstream::rdbuf() 
const [17]
-----------------------------------------------
                0.02    0.00 1000000/1000000     
std::stringstream::stringstream(__rw::__rw_openmode) [5]
[6]      8.3    0.02    0.00 1000000         
std::iostream::iostream(std::streambuf*) [6]
                0.00    0.00 2000000/14000002     data_start [9]
-----------------------------------------------
                0.01    0.00 1000000/1000000     std::iostream::~iostream() [4]
[7]      4.2    0.01    0.00 1000000         std::ostream::~ostream() [7]
-----------------------------------------------
                0.01    0.00 1000000/1000000     
std::stringstream::~stringstream() [3]
[8]      4.2    0.01    0.00 1000000         std::ios::~ios() [8]
                0.00    0.00 1000000/14000002     data_start [9]
-----------------------------------------------
                0.00    0.00 1000000/14000002     std::ios::~ios() [8]
                0.00    0.00 1000000/14000002     
std::stringstream::~stringstream() [3]
                0.00    0.00 2000000/14000002     
std::iostream::iostream(std::streambuf*) [6]
                0.00    0.00 2000000/14000002     
std::stringstream::stringstream(__rw::__rw_openmode) [5]
                0.00    0.00 3000002/14000002     main [1]
                0.00    0.00 5000000/14000002     std::string 
lex_cast<std::string, long>(long const&) [2]
[9]      0.0    0.00    0.00 14000002         data_start [9]
-----------------------------------------------
                0.00    0.00       1/1000001     main [1]
                0.00    0.00 1000000/1000001     std::string 
lex_cast<std::string, long>(long const&) [2]
[15]     0.0    0.00    0.00 1000001         std::allocator<char>::allocator() 
[15]
-----------------------------------------------
                0.00    0.00 1000000/1000000     
std::allocator<__rw::__string_ref<char, std::char_traits<char>, 
std::allocator<char> > >::destroy(__rw::__string_ref<char, 
std::char_traits<char>, std::allocator<char> >*) [19]
[16]     0.0    0.00    0.00 1000000         __rw::__string_ref<char, 
std::char_traits<char>, std::allocator<char> >::~__string_ref() [16]
-----------------------------------------------
                0.00    0.00 1000000/1000000     
std::stringstream::stringstream(__rw::__rw_openmode) [5]
[17]     0.0    0.00    0.00 1000000         std::stringstream::rdbuf() const 
[17]
-----------------------------------------------
                0.00    0.00 1000000/1000000     std::iostream::~iostream() [4]
[18]     0.0    0.00    0.00 1000000         std::istream::~istream() [18]
-----------------------------------------------
{noformat}
and index by function name:
{noformat}
   [2] std::string lex_cast<std::string, long>(long const&)
   [4] std::iostream::~iostream()
   [8] std::ios::~ios()
  [16] __rw::__string_ref<char, std::char_traits<char>, std::allocator<char> 
>::~__string_ref()
  [18] std::istream::~istream()
   [9] data_start
  [17] std::stringstream::rdbuf() const
   [7] std::ostream::~ostream()
   [1] main
  [15] std::allocator<char>::allocator()
   [5] std::stringstream::stringstream(__rw::__rw_openmode)
   [6] std::iostream::iostream(std::streambuf*)
   [3] std::stringstream::~stringstream()
{noformat}
  
> sstream ctors inefficient in reentrant modes
> --------------------------------------------
>
>                 Key: STDCXX-914
>                 URL: https://issues.apache.org/jira/browse/STDCXX-914
>             Project: C++ Standard Library
>          Issue Type: Improvement
>          Components: 27. Input/Output
>    Affects Versions: 4.1.2, 4.1.3, 4.1.4, 4.2.0, 4.2.1
>            Reporter: Martin Sebor
>            Priority: Critical
>             Fix For: 4.2.2
>
>         Attachments: stdcxx-914-gprof-gcc-4.1.2-12D.txt, 
> stdcxx-914-gprof-gcc-4.3.0-12S.txt
>
>   Original Estimate: 12h
>          Time Spent: 2.5h
>  Remaining Estimate: 9.5h
>
> As discussed in this [thread|http://markmail.org/message/hqlsw5dq23gx7d4o] 
> stream ctors in thread-safe builds are inefficient due to the initialization 
> of the mutex data member in every stream, even in those that never use it. As 
> soon as binary compatibility rules permit it we should remove the mutex 
> and/or defer its initialization until it's needed. It might be possible to 
> implement the deferred initialization as early as 4.2.2, or maybe 4.3. 
> Complete removal will need to wait until 5.0.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to