Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-34296

extern thread_local is a CPU waste

    XMLWordPrintable

Details

    Description

      In MDEV-31558 we wrongly thought that there would be minimal overhead for accessing a thread-local variable:

      extern thread_local ha_handler_stats *mariadb_stats;
      

      It turns out that in C++11, each access to an extern thread_local variable requires conditionally invoking an initialization function. In fact, we do have a custom initializer of this very variable, so that call is actually unavoidable:

      thread_local ha_handler_stats mariadb_dummy_stats;
      thread_local ha_handler_stats *mariadb_stats= &mariadb_dummy_stats;
      

      It turns out that already had a better declared thread local variable that the mariadb_stats would point to when it is not pointing to the dummy object:

      static thread_local THD *THR_THD;
       
      MYSQL_THD _current_thd() { return THR_THD; }
      

      We can access THD::handler_stats directly (well, via an accessor function, because the definition of THD is hidden from the InnoDB storage engine).

      Attachments

        Issue Links

          Activity

            People

              marko Marko Mäkelä
              marko Marko Mäkelä
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start 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.