From 78b54810a62580537b0a2df7eb781e03667d63ba Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 12 Sep 2018 15:01:46 -0700 Subject: [PATCH] Disable optimizations on windows for parsers w/ large lex functions --- src/compiler/generate_code/c_code.cc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/compiler/generate_code/c_code.cc b/src/compiler/generate_code/c_code.cc index 01c6f20d..14250037 100644 --- a/src/compiler/generate_code/c_code.cc +++ b/src/compiler/generate_code/c_code.cc @@ -106,7 +106,7 @@ class CCodeGenerator { buffer = ""; add_includes(); - add_warning_pragma(); + add_pragmas(); add_stats(); add_symbol_enum(); add_symbol_names_list(); @@ -142,12 +142,23 @@ class CCodeGenerator { line(); } - void add_warning_pragma() { + void add_pragmas() { line("#if defined(__GNUC__) || defined(__clang__)"); line("#pragma GCC diagnostic push"); line("#pragma GCC diagnostic ignored \"-Wmissing-field-initializers\""); line("#endif"); line(); + + // Compiling large lexer functions can be very slow, especially when + // using Visual Studio on Windows. Disabling optimizations is not + // ideal, but only a very small fraction of overall parse time is + // spent lexing, so the performance impact of this is pretty small. + if (main_lex_table.states.size() > 500) { + line("#ifdef _MSC_VER"); + line("#pragma optimize(\"\", off)"); + line("#endif"); + line(); + } } void add_stats() {