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.
Attachments
Issue Links
causes
MDEV-23183Infinite loop on page_validate() on corrupted page
Closed
relates to
MDEV-24973Performance schema duplicates rarely executed code for mutex operations
Closed
MDEV-35498InnoDB logger class causes significant code bloat
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.
Marko Mäkelä
added a comment - 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.
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:
Maybe it would be even better to revert back to printf-style logging at some point.
Marko Mäkelä
added a comment - 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.
People
Marko Mäkelä
Dmitriy Philimonov
Votes:
1Vote for this issue
Watchers:
5Start watching this issue
Dates
Created:
Updated:
Resolved:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
{"report":{"fcp":751.8000001907349,"ttfb":161.19999980926514,"pageVisibility":"visible","entityId":87472,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"0b745178-d204-41ba-996f-7c74b684995a","navigationType":0,"readyForUser":862.0999999046326,"redirectCount":0,"resourceLoadedEnd":490,"resourceLoadedStart":168.90000009536743,"resourceTiming":[{"duration":4.099999904632568,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bsh/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":168.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":168.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":173,"responseStart":0,"secureConnectionStart":0},{"duration":4.400000095367432,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bsh/820016/12ta74/eb142f92e4bd16bd1ef8b08c1b9d5d56/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":169.09999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":169.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":173.5,"responseStart":0,"secureConnectionStart":0},{"duration":195.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/b09d0d077992e4331b5f9ec0d3ec448c-CDN/lu2bsh/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":169.19999980926514,"connectEnd":169.19999980926514,"connectStart":169.19999980926514,"domainLookupEnd":169.19999980926514,"domainLookupStart":169.19999980926514,"fetchStart":169.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":176.80000019073486,"responseEnd":364.5,"responseStart":199.5,"secureConnectionStart":169.19999980926514},{"duration":7.400000095367432,"initiatorType":"script","name":"https://jira.mariadb.org/s/6c569cbf8087ab04e40d0bef98627457-CDN/lu2bsh/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":169.40000009536743,"connectEnd":169.40000009536743,"connectStart":169.40000009536743,"domainLookupEnd":169.40000009536743,"domainLookupStart":169.40000009536743,"fetchStart":169.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":169.40000009536743,"responseEnd":176.80000019073486,"responseStart":176.80000019073486,"secureConnectionStart":169.40000009536743},{"duration":320.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/b47ab3df14096803b180217eb8482517-CDN/lu2bsh/820016/12ta74/eb142f92e4bd16bd1ef8b08c1b9d5d56/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":169.40000009536743,"connectEnd":169.40000009536743,"connectStart":169.40000009536743,"domainLookupEnd":169.40000009536743,"domainLookupStart":169.40000009536743,"fetchStart":169.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":178.5,"responseEnd":490,"responseStart":201.69999980926514,"secureConnectionStart":169.40000009536743},{"duration":36.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":169.5,"connectEnd":169.5,"connectStart":169.5,"domainLookupEnd":169.5,"domainLookupStart":169.5,"fetchStart":169.5,"redirectEnd":0,"redirectStart":0,"requestStart":179.30000019073486,"responseEnd":206,"responseStart":204.80000019073486,"secureConnectionStart":169.5},{"duration":38,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":169.59999990463257,"connectEnd":169.59999990463257,"connectStart":169.59999990463257,"domainLookupEnd":169.59999990463257,"domainLookupStart":169.59999990463257,"fetchStart":169.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":181,"responseEnd":207.59999990463257,"responseStart":206.19999980926514,"secureConnectionStart":169.59999990463257},{"duration":9.900000095367432,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bsh/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":169.69999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":169.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":179.59999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":66.2999997138977,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":169.80000019073486,"connectEnd":169.80000019073486,"connectStart":169.80000019073486,"domainLookupEnd":169.80000019073486,"domainLookupStart":169.80000019073486,"fetchStart":169.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":185.80000019073486,"responseEnd":236.09999990463257,"responseStart":232.40000009536743,"secureConnectionStart":169.80000019073486},{"duration":13.799999713897705,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bsh/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":169.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":169.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":183.69999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":46.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/81b5d7c27af3ebc078cc4a36383678ba-CDN/lu2bsh/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":170,"connectEnd":170,"connectStart":170,"domainLookupEnd":170,"domainLookupStart":170,"fetchStart":170,"redirectEnd":0,"redirectStart":0,"requestStart":190.69999980926514,"responseEnd":216.80000019073486,"responseStart":214.80000019073486,"secureConnectionStart":170},{"duration":297.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":174.19999980926514,"connectEnd":174.19999980926514,"connectStart":174.19999980926514,"domainLookupEnd":174.19999980926514,"domainLookupStart":174.19999980926514,"fetchStart":174.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":202.69999980926514,"responseEnd":471.5,"responseStart":463.59999990463257,"secureConnectionStart":174.19999980926514},{"duration":298.40000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":174.19999980926514,"connectEnd":174.19999980926514,"connectStart":174.19999980926514,"domainLookupEnd":174.19999980926514,"domainLookupStart":174.19999980926514,"fetchStart":174.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":226.59999990463257,"responseEnd":472.59999990463257,"responseStart":467.5,"secureConnectionStart":174.19999980926514},{"duration":79.59999990463257,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":511.90000009536743,"connectEnd":511.90000009536743,"connectStart":511.90000009536743,"domainLookupEnd":511.90000009536743,"domainLookupStart":511.90000009536743,"fetchStart":511.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":558.8000001907349,"responseEnd":591.5,"responseStart":590.5999999046326,"secureConnectionStart":511.90000009536743},{"duration":40.5,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":745.3000001907349,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":745.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":785.8000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":35.299999713897705,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":751.8000001907349,"connectEnd":751.8000001907349,"connectStart":751.8000001907349,"domainLookupEnd":751.8000001907349,"domainLookupStart":751.8000001907349,"fetchStart":751.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":751.8000001907349,"responseEnd":787.0999999046326,"responseStart":787.0999999046326,"secureConnectionStart":751.8000001907349}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":30,"responseStart":161,"responseEnd":173,"domLoading":164,"domInteractive":927,"domContentLoadedEventStart":927,"domContentLoadedEventEnd":966,"domComplete":1129,"loadEventStart":1129,"loadEventEnd":1129,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":899.4000000953674},{"name":"bigPipe.sidebar-id.end","time":900.0999999046326},{"name":"bigPipe.activity-panel-pipe-id.start","time":900.4000000953674},{"name":"bigPipe.activity-panel-pipe-id.end","time":901.6999998092651},{"name":"activityTabFullyLoaded","time":979.5999999046326}],"measures":[],"correlationId":"4d3eadbbef2dd0","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":77,"dbReadsTimeInMs":14,"dbConnsTimeInMs":21,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
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.