-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
src: slim down node_v8_platform-inl.h #46926
src: slim down node_v8_platform-inl.h #46926
Conversation
7e5ddd3
to
7ef80b8
Compare
src/node_v8_platform.h
Outdated
bool initialized_ = false; | ||
|
||
#if NODE_USE_V8_PLATFORM | ||
void Initialize(int thread_pool_size) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method definitions like this - wherein a method is non-inline if NODE_USE_V8_PLATFORM
but inline otherwise - have been intentionally kept in the .h
file, as opposed to moving them to a .cc
file.
The idea being - to prevent confusion and mistakes due to code duplication of the NODE_USE_V8_PLATFORM
if-else construct, e.g.:
// src/node_v8_platform.h
class NodeTraceStateObserver {
#if NODE_USE_V8_PLATFORM
void Initialize(int thread_pool_size);
#else
inline void Initialize(int thread_pool_size);
#endif // NODE_USE_V8_PLATFORM
}
// src/node_v8_platform.cc
#if NODE_USE_V8_PLATFORM
void NodeTraceStateObserver::Initialize(int thread_pool_size) {
// ...
}
#else
inline void NodeTraceStateObserver::Initialize(int thread_pool_size) {
// ...
}
#endif // NODE_USE_V8_PLATFORM
7ef80b8
to
56af746
Compare
Ran the cpp linter. My bad for force-pushing. |
Moving code from foo-inl.h file to foo.h doesn't fix the code bloat problem. In fact, it probably makes it worse because foo.h is normally included more often than foo-inl.h. The goal of #43712 is to move method definitions that are too big/infrequently called/etc. from foo.h or foo-inl.h to foo.cc. |
@bnoordhuis Generally speaking, should binary size be the "go-to" litmus test when evaluating usefulness of this kind of refactor? My C++ is a bit rusty but I intend to continue working on #43712 to completion. |
Yes, binary size is the decisive criterion. If moving code from a .h to a .cc makes no meaningful difference, then it likely means that code is not called from many places; there are probably just one or two call sites. I'm 85% sure that applies to node_v8_platform-inl.h. Most includes of that file could probably be switched to node_v8_platform.h to no ill effect. |
@bnoordhuis Noted. Thank you. Closing the PR. |
De-inline and move big functions from
node_v8_platform-inl.h
to help reduce the binary size.Non-functional change.
Refs: #43712