1

AFAIK, the preprocessor mode is simple: you give a preprocessed source to ccache, it hashes the source and command-line args, then stores all corresponding info, like stderr, object file, etc.

But what is a direct mode and why is it much faster? What is a concept behind it?

abyss.7
  • 13,882
  • 11
  • 56
  • 100

2 Answers2

1

"direct" in "direct mode" refers to "reading header files directly without using the preprocessor". This is done because most preprocessors are relatively slow compared to just reading the include file contents. This is because the preprocessor has to do things like expanding macros to produce the correct preprocessed output. For ccache's purposes, it's enough to identify the content of the header files, not to have the content correctly preprocessed when computing the hash.

See also the How ccache works section in the ccache manual.

Joel Rosdahl
  • 846
  • 9
  • 12
  • so when should i use preprocessor mode? seems to me there is no need for that, cus direct mode can detect if the header file changes, and if that changes, hash changes, and it falls back to preprocessor mode as described in https://ccache.dev/manual/3.7.11.html#_the_direct_mode – shelper Aug 04 '20 at 18:17
  • @shelper: It's correct that ccache falls back to the preprocessor mode, so there is normally no need to disable the direct mode via configuration if that's what you mean. Even with the direct mode enabled you'll use the preprocessor mode implicitly sometimes, for instance when a source or header file is changed in such a way that the preprocessed source code remains exactly the same (e.g. when editing a comment). – Joel Rosdahl Aug 06 '20 at 06:00
0

http://ccache.samba.org/performance.html

The direct mode has higher overhead than the preprocessor mode for cache misses, but is much faster for cache hits Hope this helps you.

Vidhi
  • 89
  • 1
  • 2
  • 8