Skip to content

Commit

Permalink
Make the preemptive compilation threshold configurable
Browse files Browse the repository at this point in the history
Summary:
This diff allows specifying the preemptive compilation threshold via CompileFlags.
Users get a toggle in CLI and RuntimeConfig that allows choosing between 1. fully eager, 2. fully lazy, 3. use default thresholds ("smart"). The default is #3.

However, since we use `-O` by default, it overrides any lazy compilation when
using the `hermes` binary.

ChangeLog: [Internal] Inspector updated to use new RuntimeConfig laziness control

Reviewed By: tmikov

Differential Revision: D23356463

fbshipit-source-id: 508b7b2e6a218346c69acfec97e7891e388f0e9b
  • Loading branch information
willholen authored and facebook-github-bot committed Sep 14, 2020
1 parent 300df59 commit f34b914
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
11 changes: 8 additions & 3 deletions ReactCommon/hermes/inspector/chrome/tests/AsyncHermesRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ namespace chrome {

namespace detail = facebook::hermes::inspector::detail;

AsyncHermesRuntime::AsyncHermesRuntime()
: runtime_(facebook::hermes::makeHermesRuntime()),
executor_(
AsyncHermesRuntime::AsyncHermesRuntime(bool veryLazy)
: executor_(
std::make_unique<detail::SerialExecutor>("async-hermes-runtime")) {
using namespace std::placeholders;

auto builder = ::hermes::vm::RuntimeConfig::Builder();
if (veryLazy) {
builder.withCompilationMode(::hermes::vm::ForceLazyCompilation);
}
runtime_ = facebook::hermes::makeHermesRuntime(builder.build());

runtime_->global().setProperty(
*runtime_,
"shouldStop",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ namespace chrome {
*/
class AsyncHermesRuntime {
public:
AsyncHermesRuntime();
// Create a runtime. If veryLazy, configure the runtime to use completely
// lazy compilation.
AsyncHermesRuntime(bool veryLazy = false);
~AsyncHermesRuntime();

std::shared_ptr<HermesRuntime> runtime() {
Expand Down
10 changes: 3 additions & 7 deletions ReactCommon/hermes/inspector/chrome/tests/ConnectionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ namespace {
// the already-deallocated connection.
class TestContext {
public:
TestContext(bool waitForDebugger = false)
: conn_(runtime_.runtime(), waitForDebugger) {}
TestContext(bool waitForDebugger = false, bool veryLazy = false)
: runtime_(veryLazy), conn_(runtime_.runtime(), waitForDebugger) {}
~TestContext() {
runtime_.wait();
}
Expand Down Expand Up @@ -860,9 +860,6 @@ TEST(ConnectionTests, testSetLazyBreakpoint) {
SyncConnection &conn = context.conn();
int msgId = 1;

facebook::hermes::HermesRuntime::DebugFlags flags{};
flags.lazy = true;

asyncRuntime.executeScriptAsync(
R"(
var a = 1 + 2;
Expand All @@ -879,8 +876,7 @@ TEST(ConnectionTests, testSetLazyBreakpoint) {
foo();
)",
"url",
flags);
"url");

send<m::debugger::EnableRequest>(conn, msgId++);
expectExecutionContextCreated(conn);
Expand Down

0 comments on commit f34b914

Please sign in to comment.