[MDEV-22721] Remove bloat caused by InnoDB logger class Created: 2020-05-26  Updated: 2021-02-24  Resolved: 2020-06-04

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - InnoDB
Affects Version/s: 10.2.2, 10.3.0, 10.4.0, 10.5.0, 10.5.3
Fix Version/s: 10.5.4, 10.2.33, 10.3.24, 10.4.14

Type: Bug Priority: Minor
Reporter: Dmitriy Philimonov Assignee: Marko Mäkelä
Resolution: Fixed Votes: 1
Labels: performance

Issue Links:
Problem/Incident
causes MDEV-23183 Infinite loop on page_validate() on c... Closed
Relates
relates to MDEV-24973 Performance schema duplicates rarely ... Closed

 Description   

Default implementation of InnoDB logger class uses std::stringstream inside.
STL streams are famous for generation lots of bloat code after compiling.

Usage of logger class in hot functions, which is typical for error handling,
generates a lot of code which is inlined right in the invocation point, and
99.99% of time this code isn't used. This leads to a huge instruction cache
waste.

We can point the compiler at the fact, that any logging is an expremely rare
operation for database, so the compiler can reduce unnecessary inlining and
pessimize 'cold' logging branches, meanwhile optimize really hot branches
and reduce intruction case misses.

Profit: in our tests, this optimization results in up to 2% performance
increase in sysbench OLTP PS/RO/RW tests.

Suggested fix:
Mark all public logger method and all derived class contructors with 'cold'
and 'noinline' attibutes.



 Comments   
Comment by Marko Mäkelä [ 2020-05-27 ]

I would expect that any output to the error log is rarely invoked. I have tried to declare some functions with ATTRIBUTE_COLD and some conditions with UNIV_UNLIKELY, but I have not measured the impact, and surely we could do more. I have not played with the noinline attribute, which could be low-hanging fruit.

I tentatively set fixVersion to 10.6. If the fix turns out to be a simple addition of function attributes to a few places, then I think that it should be doable in GA versions.

Comment by Marko Mäkelä [ 2020-06-04 ]

I made an experiment where I added explicit instantiation of the needed ib::logger::operator<<() member functions, added UNIV_UNLIKELY hints to callers, and trimmed some useless parts of output as well.

I managed to shrink the size of the stripped RelWithDebInfo 10.2 executable that was compiled by GCC 9.3.0 for AMD64 by some 60 KiB.

Then, I checked the disassembly, and it looks like the explicitly instantiated functions are adding (not removing) bloat, by wrapping simple function calls. With inline function definition but noinline attribute, the savings increased to 86,016 bytes.

Probably the biggest improvement was achieved by dumbing down the special treatment of fixed-length string constants:

  template<size_t N> logger& operator<<(const char (&rhs)[N])
  { return *this << static_cast<const char*>(rhs); }

Maybe it would be even better to revert back to printf-style logging at some point.

Generated at Thu Feb 08 09:16:56 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.