[Nfd-dev] Avoid inline functions to reduce code size bloat

Alex Afanasyev alexander.afanasyev at ucla.edu
Sun Feb 1 14:33:04 PST 2015

Virtual methods are not normally inlined by the compiler at all.  In most cases it is impossible by the virtue of virtual dispatch (in some   cases compiler can be smart, but it is up to the compiler).  Conversation about “code bloat” for me is moot here.

Implementing something in header file is just a choice of developer convenience in some cases, as one referenced about HyperKeyLocatorNameChecker.


> On Feb 1, 2015, at 8:58 AM, Thompson, Jeff <jefft0 at remap.ucla.edu> wrote:
> Bloat is especially a problem with inline virtual functions. This is because every bit of code that instantiates a class has to make a copy of the code for every inline virtual function in that class, even if it doesn't call the function. This is because the instantiated object can be passed to another piece of code which could call one of the virtual functions, so it must be defined. And since it is inline, the code must be defined at the place where the object is instantiated.
> For example, see the 20-line inline virtual function HyperKeyLocatorNameChecker::check
> https://github.com/named-data/ndn-cxx/blob/5ec0ee3b1e90f0b3c44f74430cd080fa583e16dc/src/security/conf/key-locator-checker.hpp#L196 <https://github.com/named-data/ndn-cxx/blob/5ec0ee3b1e90f0b3c44f74430cd080fa583e16dc/src/security/conf/key-locator-checker.hpp#L196>
> Every piece of code which instantiates a HyperKeyLocatorNameChecker must include the code for HyperKeyLocatorNameChecker::check, even if it does't call it.
> Of course, if the virtual functions of a class are not inline, but are defined in the class's .cpp file, then this problem is avoided. Therefore, at least inline virtual functions should not be used.
> - Jeff T
> From: Junxiao Shi <shijunxiao at email.arizona.edu <mailto:shijunxiao at email.arizona.edu>>
> Date: Saturday, January 31, 2015 at 22:23
> To: nfd-dev <nfd-dev at lists.cs.ucla.edu <mailto:nfd-dev at lists.cs.ucla.edu>>
> Subject: [Nfd-dev] Avoid inline functions to reduce code size bloat
> Dear folks
> Back in June, in issue 1694, I have pointed out that ndn-cxx has a tendency of over-using inline functions.
> According to C++ Dos and Don'ts <http://www.chromium.org/developers/coding-style/cpp-dos-and-donts#TOC-Stop-inlining-code-in-headers> from Chromium project, using too much inline functions creates additional work for the linker, because every file that includes those headers would emit a version of an inline function in the object file (.o), and the linker has to eliminate those duplicates.
> There's also evidence that inline functions can lead to binary size bloat, which is bad news of devices with small memory or storage, such as home routers and IoT gadgets. Even if ndn-cxx can fit into those devices, bloated binaries will consume precious memory space, and reduce available memory for ContentStore.
> A decision was made in 20140708 conference call <http://redmine.named-data.net/issues/1694#note-6> that we should stop adding new inline functions unless they are trivial getters/setters, but fixing old code is low priority.
> Of course, if a function is template, and all possible template parameters are not known in advance, it can be inline.
> During the review of issue 2183, I suggested Change Owner to move inline functions into .cpp, as per the decision above.
> However, this suggestion was rejected.
> The reply was "whatever you saying. I'm refusing to do change here". No valid reason is given with this reply.
> To finally resolve this and similar disputes, I request a review on the decision about inline function usage.
> Please give your opinion about where inline functions should be used, along with necessary reasons and citations.
> Yours, Junxiao
> _______________________________________________
> Nfd-dev mailing list
> Nfd-dev at lists.cs.ucla.edu
> http://www.lists.cs.ucla.edu/mailman/listinfo/nfd-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.lists.cs.ucla.edu/pipermail/nfd-dev/attachments/20150201/9d86cd77/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 841 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://www.lists.cs.ucla.edu/pipermail/nfd-dev/attachments/20150201/9d86cd77/attachment.bin>

More information about the Nfd-dev mailing list