Open
Description
Inspired by me setting a breakpoint on a function and gdb telling me there are 12 locations...
The idea behind the *-inl.h
files is to provide inline definitions of short functions. Large gobs of code don't belong in them because they negatively impact:
- Compile times
- Binary size (duplication)
- Run-time performance (instruction cache pressure)
Rules of thumb:
- Functions with few or infrequent callers should (judgment call) live in a
.cc
file - Functions over 4-5 lines that aren't template functions should live in a
.cc
file - Macros like
CHECK(..)
expand to multiple lines of code and should be counted as such
Good (short, many callers):
Lines 56 to 58 in 7d13f5e
Not good (big, only two infrequent callers):
Lines 349 to 365 in 7d13f5e
Questionable (single infrequent caller):
Lines 510 to 518 in 7d13f5e
The most commonly used *-inl.h
files are:
$ find src -type f | xargs perl -ne 'print "$1\n" if /#\s*include "([^"]+-inl.h)"/' | sort | uniq -c | sort -r | head -9
91 env-inl.h
74 util-inl.h
52 memory_tracker-inl.h
42 base_object-inl.h
35 async_wrap-inl.h
29 debug_utils-inl.h
19 threadpoolwork-inl.h
18 node_process-inl.h
15 stream_base-inl.h