mapbox / mapbox/variant

Remove VARIANT_INLINE

Open
#166 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
384
Forks
96
PR merge metrics
No merged PRs in 30d

Description

It appears that some inadvertent changes have disabled the effect of the `VARIANT_INLINE` macro in debug builds on Windows and release builds on all other platforms, by commenting out the replacement text of the macro.

https://github.com/mapbox/variant/blob/256ddd55582bb7c06c342315dbacc6a42fee4b34/include/mapbox/variant.hpp#L39
https://github.com/mapbox/variant/blob/256ddd55582bb7c06c342315dbacc6a42fee4b34/include/mapbox/variant.hpp#L43

In those cases, the methods tagged with `VARIANT_INLINE` were inlined or not according to the default behavior of the compiler and optimization settings.

In my tests with mapbox-gl-native, removing the comments and thus restoring `VARIANT_INLINE` to its intended function in the release build causes a 2.5% size increase in the resulting binary (Apple clang 9, building with `-Os`):

```
VM SIZE FILE SIZE
-------------- --------------
+3.9% +116Ki __TEXT,__text +116Ki +3.9%
+283% +2.50Ki Table of Non-instructions +2.50Ki +283%
+2.2% +1.36Ki Code Signature +1.36Ki +2.2%
+11% +368 [__LINKEDIT] 0 [ = ]
+0.0% +48 __TEXT,__const +48 +0.0%
-1.2% -224 Function Start Addresses -224 -1.2%
-2.2% -1.66Ki __TEXT,__unwind_info -1.66Ki -2.2%
-56.1% -1.89Ki [__TEXT] -1.89Ki -56.7%
-2.3% -9.11Ki __TEXT,__gcc_except_tab -9.11Ki -2.3%
+2.5% +108Ki TOTAL +107Ki +2.5%
```

I suggest we remove the `VARIANT_INLINE` macro entirely, the rationale being:

* The compiler is best positioned to determine whether or not to inline these methods, based on program analysis and the developer's chosen optimization settings.
* `VARIANT_INLINE` has effectively been a no-op in release builds on the majority of platforms since 372d7c88fe796a138d0e578328914ac80e5a949a, and we haven't noticed any issues with that.
* Restoring it to force inlining in release builds seems to increase the binary size, the opposite of the desired effect.

cc @artemp @springmeyer @lightmare

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in include/mapbox/variant.hpp at the referenced lines and search the repository for VARIANT_INLINE uses. Remove the macro and its references, then verify that the C++11/C++14 library still builds and its existing tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.