This is a test patch that defaults the compile flags to optimize for size

The build types:
Release - set to Os
Debug   - untouched (-g -O0)

To apply this patch
$ cd node-src
$ patch -Np1 < this.patch

diff -ruN node-v16.14.0/common.gypi node-patched/common.gypi
--- node-v16.14.0/common.gypi	2022-02-08 12:37:46.000000000 +0000
+++ node-patched/common.gypi	2022-03-05 12:25:09.072611513 +0000
@@ -186,7 +186,7 @@
             }],
           ],
         },
-        'cflags': [ '-O3' ],
+        'cflags': [ '-Os' ],
         'conditions': [
           ['enable_lto=="true"', {
             'cflags': ['<(lto)'],
@@ -246,16 +246,16 @@
             ],
             'EnableFunctionLevelLinking': 'true',
             'EnableIntrinsicFunctions': 'true',
-            'FavorSizeOrSpeed': 1,          # /Ot, favor speed over size
+            'FavorSizeOrSpeed': 2,          # Favor size over speed
             'InlineFunctionExpansion': 2,   # /Ob2, inline anything eligible
             'OmitFramePointers': 'true',
-            'Optimization': 3,              # /Ox, full optimization
+            'Optimization': 's',            # optimize for size
             'RuntimeLibrary': '<(MSVC_runtimeType)',
             'RuntimeTypeInfo': 'false',
           }
         },
         'xcode_settings': {
-          'GCC_OPTIMIZATION_LEVEL': '3', # stop gyp from defaulting to -Os
+          'GCC_OPTIMIZATION_LEVEL': 's', # set gyp default to -Os
         },
       }
     },
diff -ruN node-v16.14.0/deps/llhttp/common.gypi node-patched/deps/llhttp/common.gypi
--- node-v16.14.0/deps/llhttp/common.gypi	2022-02-08 12:37:46.000000000 +0000
+++ node-patched/deps/llhttp/common.gypi	2022-03-05 12:25:09.072611513 +0000
@@ -1,6 +1,6 @@
 {
   'target_defaults': {
-    'default_configuration': 'Debug',
+    'default_configuration': 'Release',
     'configurations': {
       # TODO: hoist these out and put them somewhere common, because
       #       RuntimeLibrary MUST MATCH across the entire project
@@ -15,7 +15,7 @@
       },
       'Release': {
         'defines': [ 'NDEBUG' ],
-        'cflags': [ '-Wall', '-Wextra', '-O3' ],
+        'cflags': [ '-Wall', '-Wextra', '-Os' ],
         'msvs_settings': {
           'VCCLCompilerTool': {
             'RuntimeLibrary': 0, # static release
@@ -32,7 +32,7 @@
       'VCLibrarianTool': {
       },
       'VCLinkerTool': {
-        'GenerateDebugInformation': 'true',
+        'GenerateDebugInformation': 'false',
       },
     },
     'conditions': [
diff -ruN node-v16.14.0/deps/uv/common.gypi node-patched/deps/uv/common.gypi
--- node-v16.14.0/deps/uv/common.gypi	2022-02-08 12:37:47.000000000 +0000
+++ node-patched/deps/uv/common.gypi	2022-03-05 12:25:09.072611513 +0000
@@ -7,7 +7,7 @@
   },
 
   'target_defaults': {
-    'default_configuration': 'Debug',
+    'default_configuration': 'Release',
     'configurations': {
       'Debug': {
         'defines': [ 'DEBUG', '_DEBUG' ],
@@ -46,7 +46,7 @@
       'Release': {
         'defines': [ 'NDEBUG' ],
         'cflags': [
-          '-O3',
+          '-Os',
         ],
         'msvs_settings': {
           'VCCLCompilerTool': {
@@ -57,8 +57,8 @@
                 'RuntimeLibrary': 2, # /MD DLL release
               }],
             ],
-            'Optimization': 3, # /Ox, full optimization
-            'FavorSizeOrSpeed': 1, # /Ot, favour speed over size
+            'Optimization': 's', # optimize for size
+            'FavorSizeOrSpeed': 2, # Favor size over speed
             'InlineFunctionExpansion': 2, # /Ob2, inline anything eligible
             'WholeProgramOptimization': 'true', # /GL, whole program optimization, needed for LTCG
             'OmitFramePointers': 'true',
diff -ruN node-v16.14.0/tools/msvs/msi/custom_actions.vcxproj node-patched/tools/msvs/msi/custom_actions.vcxproj
--- node-v16.14.0/tools/msvs/msi/custom_actions.vcxproj	2022-02-08 12:37:50.000000000 +0000
+++ node-patched/tools/msvs/msi/custom_actions.vcxproj	2022-03-05 12:25:09.072611513 +0000
@@ -186,7 +186,7 @@
       <AdditionalDependencies>msi.lib;dutil.lib;wcautil.lib;version.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <AdditionalLibraryDirectories>$(WixSdkDir)\lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
       <ModuleDefinitionFile>custom_actions.def</ModuleDefinitionFile>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <GenerateDebugInformation>false</GenerateDebugInformation>
       <SubSystem>Windows</SubSystem>
       <OptimizeReferences>true</OptimizeReferences>
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
@@ -212,7 +212,7 @@
       <AdditionalDependencies>msi.lib;dutil.lib;wcautil.lib;version.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <AdditionalLibraryDirectories>$(WixSdkDir)\lib\ARM64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
       <ModuleDefinitionFile>custom_actions.def</ModuleDefinitionFile>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <GenerateDebugInformation>false</GenerateDebugInformation>
       <SubSystem>Windows</SubSystem>
       <OptimizeReferences>true</OptimizeReferences>
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
@@ -238,7 +238,7 @@
       <AdditionalDependencies>msi.lib;dutil.lib;wcautil.lib;version.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <AdditionalLibraryDirectories>$(WixSdkDir)\lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
       <ModuleDefinitionFile>custom_actions.def</ModuleDefinitionFile>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <GenerateDebugInformation>false</GenerateDebugInformation>
       <SubSystem>Windows</SubSystem>
       <OptimizeReferences>true</OptimizeReferences>
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
diff -ruN node-v16.14.0/tools/v8_gypfiles/toolchain.gypi node-patched/tools/v8_gypfiles/toolchain.gypi
--- node-v16.14.0/tools/v8_gypfiles/toolchain.gypi	2022-02-08 12:37:51.000000000 +0000
+++ node-patched/tools/v8_gypfiles/toolchain.gypi	2022-03-05 12:26:40.265950183 +0000
@@ -1303,11 +1303,15 @@
           ['OS=="linux" or OS=="freebsd" or OS=="openbsd" or OS=="netbsd" \
             or OS=="aix"', {
             'cflags!': [
-              '-Os',
+              '-O3',
+              '-O2',
+              '-O1',
+              '-O0',
             ],
             'cflags': [
               '-fdata-sections',
               '-ffunction-sections',
+              '-Os',
             ],
             'conditions': [
               # Don't use -O3 with sanitizers.
