-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
43 lines (22 loc) · 1.82 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
// EXECUTABLE BASE SIZE WITHOUT ADDING "ImGuiImplementation.cpp" TO SOURCE = 11KB
// ADDING "ImGuiImplementation.cpp" AS SOURCE INCREASES EXECUTABLE SIZE TO 34KB
// JUST ADDING THIS AS SOURCE DOES THIS, EVEN THOUGH main.cpp DOESN'T REFERENCE ANYTHING
// WITH WHOLE PROGRAM OPTIMIZATION TURNED ON IT DROPS THE COMPILE TIME FROM 26 SECONDS TO 5 SECONDS
// A MICROSOFT MEMBER SAID THAT THIS IS BECAUSE THE COMPILER OPTIMIZES OUT ALL THE PATHS NOT TAKEN AND THEREFORE DOESN'T COMPILE WHAT ISN'T USED
// SO IT SEEMS THE LINKER IS DOING THE CORRECT THING AND LINKING ONLY SELECTIVELY.
// ADDING THE /Gy (function-level linking), WHICH IS SUPPOSED TO GIVE EACH VARIABLE AND FUNCTION ITS OWN COMDAT SECTION, THEREBY MAKING IT POSSIBLE TO EXCLUDE INDIVIDUAL FUNCTIONS THAT ARE NOT USED, DOES NOTHING THE SIZE
// FLAG /OPT:REF [[eliminates functions and data that are never referenced]] DOES NOTHING
#include "./ImGuiFiles/imgui.h" // INCLUDING HEADER DOESN'T DO ANYTHING TO SIZE (AS EXPECTED)
int main()
{
std::cout << 7; // JUST DO ANYTHING TO USE THE STANDARD LIBRARY AS A BASE CASE
//ImGui::CreateContext(); // UNCOMMENTING THIS INCREASES EXECUTABLE SIZE FROM 34KB TO 58KB
//ImGui::NewFrame(); // UNCOMMENTING THIS INCREASES EXECUTABLE SIZE FROM 58KB TO 180KB
// THE TWO CALLS ABOVE INCREASED THE EXECUTABLE SIZE AS WOULD BE EXPECTED
// IT SEEMS THE LINKER IS ADDING ONLY THE REQUIRED CODE???
// HOWEVER FROM THE BASE CASE (ONLY AN std::cout statement) ADDING THE ImGuiImplementation.cpp SOURCE (WITHOUT ANY REFERENCE TO IT) THE SIZE ALMOST TRIPLES
// IN THIS CASE IT'S ONLY AN INCREASE OF ABOUT 20KB (ALBEIT TRIPLE THE SIZE) BUT IN ANOTHER EXAMPLE IT ADDED UP TO MEGABYTES. I'M TRYING TO FIGURE OUT WHY THIS BEHAVIOUR HAPPENS.
//Gy (function-level linking) DOES ABSOLUTELY NOTHING IN ALL CASES I TESTED
return 0;
}