Rethink use of thread_local #18678

issue MarcoFalke opened this issue on April 16, 2020
  1. MarcoFalke commented at 9:10 PM on April 16, 2020: member

    Merely compiling Bitcoin Core with thread_local seems to correlate with massively degraded performance for both the RPC and P2P interface on low-end machines. See for example:

    If thread_local really is the source of the performance degradation, it should be disabled by default and only enabled by --enable-debug (for use in lock order debugging).

  2. MarcoFalke added the label Bug on Apr 16, 2020
  3. bitcoin deleted a comment on Apr 17, 2020
  4. laanwj commented at 9:20 AM on April 30, 2020: member

    Yes, it's onlly used in one place, given how static our thread setup is I think we could easily replace it with a map of thread id to name.

    Though naively I'd expect thread-local to be faster than a mutex-protected map. I'm surprised: do we really look up the thread name that often that this matters?

  5. laanwj cross-referenced this on Apr 30, 2020 from issue bench: Add logging benchmark by MarcoFalke
  6. MarcoFalke commented at 4:01 PM on April 30, 2020: member

    For some reason it seems to cause a slowdown from 6 minutes to 60 minutes. I don't know where that came from, but if caused by thread_local, this is unacceptable.

  7. laanwj cross-referenced this on May 2, 2020 from issue threadnames: don't allocate memory in ThreadRename by jb55
  8. laanwj commented at 8:54 AM on May 2, 2020: member

    It's only used in one place. Do we have statistics how often these are called?

    Or does using thread_local at all, say, even in a place that is never called (or only once), add execution overhead throughout the entire program?

    I cannot quite reproduce this locally FWIW. Someone with an affected configuration should do a bit more probing.

  9. laanwj referenced this in commit 78031df4b1 on May 2, 2020
  10. laanwj cross-referenced this on May 2, 2020 from issue refactor: Replace thread_local use with a mutex-protected map by laanwj
  11. laanwj commented at 10:47 AM on May 2, 2020: member

    Can someone suffering from (assumed) thread_local related performance issues please test #18851?

  12. laanwj referenced this in commit c7933899e9 on May 2, 2020
  13. MarcoFalke removed the label Bug on May 2, 2020
  14. MarcoFalke added the label Brainstorming on May 2, 2020
  15. laanwj commented at 2:05 PM on May 4, 2020: member

    Closing as there is no thread_local issue (see #18538 (comment)).

  16. laanwj closed this on May 4, 2020

  17. bitcoin locked this on Feb 15, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-20 06:54 UTC