Paralellize analyzeProgram
commitedf1bc9111112902907f88be43888b0cd7467bb0
authorMark Williams <mwilliams@fb.com>
Tue, 15 Aug 2017 18:51:06 +0000 (15 11:51 -0700)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Tue, 15 Aug 2017 19:02:50 +0000 (15 12:02 -0700)
treef3fe4b73c58c40653dd8d8aba1461842df9fe1bc
parentc2a02c819efe5d16620b613f1ed6aa9ff8a81a8f
Paralellize analyzeProgram

Summary:
A few analysis steps needed cleaning up, and a few locks were
required, but it was mostly ready to go.

To help find places we were modifying global state in the
AnalysisResult, I canged the AnalysisResultPtr argument of
Construct::analyzeProgram to an AnalysisResultConstPtr. Once done,
this only decreased the time for analyze all by about 15% on a 56 core
machine, so clearly something was not parallelizing well.

Running perf showed there was no lock contention, and very little
context switching; but all the time was being spent in
AnalysisResult::analyzeProgram(ConstructPtr), which is really just a
recursive walk calling Construct::analyzeProgram as it goes.

A while ago ricklavoie had mentioned that passing shared_ptrs around was
very expensive; I'd expermented with that a long time ago, and after
one huge win (replacing vectors of shared_ptrs that got copied around
a lot with vectors of hphp_raw_ptrs), was unable to get any
others. But based on perf, I rewrote all the getNthKid functions to
return ConstructRawPtr and analyzeProgram to take a ConstructRawPtr,
and it made no difference at all.

Then I realized the problem is with the AnalysisResultPtr we were
passing around. Most of the shared pointers don't really matter; its a
bit more expensive, but only one thread is using any given pointer at
any given time so its only an extra couple of memory operations. But
the AnalysisResultPtr is global; every single thread is doing atomic
incs and decs the same shared pointer, so almost all are missing in
the cache. So I changed all the AnalysisResultConstPtrs that I'd just
added to AnalysisResultConstRawPtrs, and got a 6x win.

There's clearly more available - it should have been a 30x win, but
I'll do that in a followup (which will probably help preOptimize too).

Reviewed By: alexeyt

Differential Revision: D5619284

fbshipit-source-id: b1c8f67f4b6b4a88164997dc379d238b218c59bb
55 files changed:
hphp/compiler/analysis/analysis_result.cpp
hphp/compiler/analysis/analysis_result.h
hphp/compiler/analysis/class_scope.cpp
hphp/compiler/analysis/class_scope.h
hphp/compiler/analysis/file_scope.cpp
hphp/compiler/analysis/file_scope.h
hphp/compiler/analysis/variable_table.cpp
hphp/compiler/analysis/variable_table.h
hphp/compiler/construct.h
hphp/compiler/expression/assignment_expression.cpp
hphp/compiler/expression/assignment_expression.h
hphp/compiler/expression/class_constant_expression.cpp
hphp/compiler/expression/class_constant_expression.h
hphp/compiler/expression/class_expression.cpp
hphp/compiler/expression/class_expression.h
hphp/compiler/expression/closure_expression.cpp
hphp/compiler/expression/closure_expression.h
hphp/compiler/expression/constant_expression.cpp
hphp/compiler/expression/constant_expression.h
hphp/compiler/expression/dynamic_function_call.cpp
hphp/compiler/expression/dynamic_function_call.h
hphp/compiler/expression/function_call.cpp
hphp/compiler/expression/function_call.h
hphp/compiler/expression/include_expression.cpp
hphp/compiler/expression/include_expression.h
hphp/compiler/expression/new_object_expression.cpp
hphp/compiler/expression/new_object_expression.h
hphp/compiler/expression/object_method_expression.cpp
hphp/compiler/expression/object_method_expression.h
hphp/compiler/expression/object_property_expression.cpp
hphp/compiler/expression/object_property_expression.h
hphp/compiler/expression/scalar_expression.cpp
hphp/compiler/expression/scalar_expression.h
hphp/compiler/expression/simple_function_call.cpp
hphp/compiler/expression/simple_function_call.h
hphp/compiler/expression/simple_variable.cpp
hphp/compiler/expression/simple_variable.h
hphp/compiler/expression/static_member_expression.cpp
hphp/compiler/expression/static_member_expression.h
hphp/compiler/statement/catch_statement.cpp
hphp/compiler/statement/catch_statement.h
hphp/compiler/statement/class_statement.cpp
hphp/compiler/statement/class_statement.h
hphp/compiler/statement/class_variable.cpp
hphp/compiler/statement/class_variable.h
hphp/compiler/statement/interface_statement.cpp
hphp/compiler/statement/interface_statement.h
hphp/compiler/statement/return_statement.cpp
hphp/compiler/statement/return_statement.h
hphp/compiler/statement/static_statement.cpp
hphp/compiler/statement/static_statement.h
hphp/compiler/statement/switch_statement.cpp
hphp/compiler/statement/switch_statement.h
hphp/compiler/statement/use_declaration_statement_fragment.h
hphp/util/deprecated/declare-boost-types.h