From 97cf4e0e061c6cecb87eec38d4c0bac389d838f7 Mon Sep 17 00:00:00 2001 From: mwilliams Date: Wed, 13 Mar 2013 09:03:56 -0700 Subject: [PATCH] Limit the number of blocks handled by TraceBuilder::optimizeTrace It appears to be O(N^3) in the number of blocks (a quick glance at the code suggested N^2, but 1000 blocks took about .5s to process while 2000 blocks took 4; 19000 blocks was nowhere near finished in an hour). A better representation of the dominators would probably solve this - but would also take *much* more space. Having more than 1000 blocks appears to be extremely rare, so this seems like a reasonable solution for now. --- hphp/runtime/base/runtime_option.h | 1 + hphp/runtime/vm/translator/hopt/tracebuilder.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/hphp/runtime/base/runtime_option.h b/hphp/runtime/base/runtime_option.h index 0016056cb..cece553dd 100644 --- a/hphp/runtime/base/runtime_option.h +++ b/hphp/runtime/base/runtime_option.h @@ -414,6 +414,7 @@ public: F(bool, HHIRGenericDtorHelper, true) \ F(bool, HHIRCse, true) \ F(bool, HHIRSimplification, true) \ + F(uint32_t, HHIRSimplificationMaxBlocks,1000) \ F(bool, HHIRGenOpts, true) \ F(bool, HHIRJumpOpts, true) \ F(bool, HHIRExtraOptPass, true) \ diff --git a/hphp/runtime/vm/translator/hopt/tracebuilder.cpp b/hphp/runtime/vm/translator/hopt/tracebuilder.cpp index 4f2b0cdbb..351ed72a3 100644 --- a/hphp/runtime/vm/translator/hopt/tracebuilder.cpp +++ b/hphp/runtime/vm/translator/hopt/tracebuilder.cpp @@ -1522,6 +1522,12 @@ void TraceBuilder::optimizeTrace() { m_enableCse = RuntimeOption::EvalHHIRCse; m_enableSimplification = RuntimeOption::EvalHHIRSimplification; if (!m_enableCse && !m_enableSimplification) return; + if (m_trace->getBlocks().size() > + RuntimeOption::EvalHHIRSimplificationMaxBlocks) { + // TODO CSEHash::filter is very slow for large block sizes + // t2135219 should address that + return; + } BlockList sortedBlocks = sortCfg(m_trace.get(), m_irFactory); IdomVector idoms = findDominators(sortedBlocks); clearTrackedState();