Repository navigation
Make *-inl.h slim again #43712
Copy link
Copy link
Closed as not planned
Labels
c++Issues and PRs that require attention from people who are familiar with C++.Issues and PRs that require attention from people who are familiar with C++.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
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
.ccfile - Functions over 4-5 lines that aren't template functions should live in a
.ccfile - 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
| inline v8::Isolate* IsolateData::isolate() const { | |
| return isolate_; | |
| } |
Not good (big, only two infrequent callers):
Lines 349 to 365 in 7d13f5e
| inline void Environment::AssignToContext(v8::Local<v8::Context> context, | |
| const ContextInfo& info) { | |
| context->SetAlignedPointerInEmbedderData( | |
| ContextEmbedderIndex::kEnvironment, this); | |
| // Used by Environment::GetCurrent to know that we are on a node context. | |
| context->SetAlignedPointerInEmbedderData( | |
| ContextEmbedderIndex::kContextTag, Environment::kNodeContextTagPtr); | |
| // Used to retrieve bindings | |
| context->SetAlignedPointerInEmbedderData( | |
| ContextEmbedderIndex::kBindingListIndex, &(this->bindings_)); | |
| #if HAVE_INSPECTOR | |
| inspector_agent()->ContextCreated(context, info); | |
| #endif // HAVE_INSPECTOR | |
| this->async_hooks()->AddContext(context); | |
| } |
Questionable (single infrequent caller):
Lines 510 to 518 in 7d13f5e
| inline void Environment::TryLoadAddon( | |
| const char* filename, | |
| int flags, | |
| const std::function<bool(binding::DLib*)>& was_loaded) { | |
| loaded_addons_.emplace_back(filename, flags); | |
| if (!was_loaded(&loaded_addons_.back())) { | |
| loaded_addons_.pop_back(); | |
| } | |
| } |
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.hReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
c++Issues and PRs that require attention from people who are familiar with C++.Issues and PRs that require attention from people who are familiar with C++.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
Activity
src: slim down env-inl.h
kvakil commentedon Jul 22, 2022
I ran
rtagsand hacked together something to put the results into SQLite.The line count is approximate (it's literally based on the number of visual lines
the function takes up), but looks to already identify some big ones:
non-template inlined functions which are >= 8 lines
Also can look at number of callers. There are some mistakes here, f.ex. some
are marked as having zero callers when they clearly have some.
non-template inlined functions with <= 2 callsites
Hopefully this provides a burndown list for people looking to work on this.
Here is a (gzipped) copy of the database for those looking for a
finer-grained analysis: inl.db.gz
src: slim down env-inl.h
src: slim down env-inl.h
src: slim down env-inl.h
lilsweetcaligula commentedon Mar 5, 2023
@bnoordhuis I have refactored
stream_base-inl.hand managed to get the binary size down by 4 bytes (in 9 compilations out of 10). Would you accept a PR?bnoordhuis commentedon Mar 6, 2023
@lilsweetcaligula I'm going to guess most calls come from src/stream_base.cc if moving code around only slims down the binary by 4 bytes. But sure, pull request welcome.
src: slim down stream_base-inl.h
src: slim down stream_base-inl.h
src: slim down stream_base-inl.h
src: slim down stream_base-inl.h
github-actions commentedon Jun 25, 2026
This issue has been marked as stale due to 210 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.
github-actions commentedon Jul 26, 2026
This issue has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 120 days).
If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.