Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add libdeno_nosnapshot source_set #359

Merged
merged 12 commits into from
Jul 12, 2018
Merged

Add libdeno_nosnapshot source_set #359

merged 12 commits into from
Jul 12, 2018

Conversation

f-a-a
Copy link

@f-a-a f-a-a commented Jul 11, 2018

This PR attempts to solve #311.

I wouldn't expect for this PR to be merged right away, but this is a proof of concept I've been experimenting with after taking a stab at it.

This PR introduces a new src/from_filesystem.cc that is akin to src/from_snapshot.cc except that instead of initializing the v8 context with StartupBlob_snapshot(), it loads js from filesystem using the InitializeContext exposed in internal.h.

It doesn't introduce a new target as @ry suggested in the issue. Instead, a is_debug check in BUILD.gn will conditionally build libdeno_nosnapshot if it is true.
It does now!

Benchmarks when adding new deno.print to main.ts file:

master
ninja -v -C out/Debug deno  47.14s user 3.42s system 109% cpu 46.232 total
deno_nosnapshot
ninja -v -C out/Debug deno  9.82s user 1.27s system 139% cpu 7.947 total
master build log

ninja: Entering directory `out/Debug'
[1/1] ../../third_party/v8/buildtools/mac/gn --root=../.. -q gen .
[1/12] ccache ../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF obj/deno_nosnapshot/binding.o.d -DV8_DEPRECATION_WARNINGS -DNO_TCMALLOC -DCHROMIUM_BUILD -DFIELDTRIAL_TESTING_ENABLED -D_LIBCPP_HAS_NO_ALIGNED_ALLOCATION -DCR_XCODE_VERSION=0941 -DCR_CLANG_REVISION=\"335864-1\" -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE=0 -D_DEBUG -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DWTF_USE_DYNAMIC_ANNOTATIONS=1 -DDEBUG -DV8_ENABLE_CHECKS -DV8_EMBEDDER_STRING=\"-deno\" -DENABLE_DISASSEMBLER -DV8_TYPED_ARRAY_MAX_SIZE_IN_HEAP=64 -DENABLE_MINOR_MC -DOBJECT_PRINT -DVERIFY_HEAP -DV8_TRACE_MAPS -DV8_ENABLE_ALLOCATION_TIMEOUT -DV8_ENABLE_FORCE_SLOW_PATH -DV8_ENABLE_CHECKS -DENABLE_HANDLE_ZAPPING -DV8_USE_SNAPSHOT -DV8_CONCURRENT_MARKING -DV8_CHECK_MICROTASKS_SCOPES_CONSISTENCY -DV8_EMBEDDED_BUILTINS -DV8_TARGET_ARCH_X64 -DDEBUG -DDISABLE_UNTRUSTED_CODE_MITIGATIONS -I../.. -Igen -I../../third_party/v8 -I../../third_party/v8/include -Igen/third_party/v8/include -fno-strict-aliasing -fstack-protector-strong -Wno-builtin-macro-redefined -D__DATE__= -D__TIME__= -D__TIMESTAMP__= -fcolor-diagnostics -fmerge-all-constants -Xclang -mllvm -Xclang -instcombine-lower-dbg-declare=0 -no-canonical-prefixes -arch x86_64 -Wall -Wextra -Wimplicit-fallthrough -Wthread-safety -Wunguarded-availability -Wno-missing-field-initializers -Wno-unused-parameter -Wno-c++11-narrowing -Wno-covered-switch-default -Wno-unneeded-internal-declaration -Wno-undefined-var-template -Wno-address-of-packed-member -Wno-nonportable-include-path -Wno-user-defined-warnings -Wno-unused-lambda-capture -Wno-null-pointer-arithmetic -Wno-enum-compare-switch -Wno-ignored-pragma-optimize -fno-omit-frame-pointer -g1 -isysroot ../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -mmacosx-version-min=10.9.0 -Wheader-hygiene -Wstring-conversion -Wtautological-overlap-compare -Wmissing-field-initializers -Winconsistent-missing-override -Wunreachable-code -Wshorten-64-to-32 -O3 -fvisibility=default -Wno-undefined-bool-conversion -Wno-tautological-undefined-compare -std=c++14 -stdlib=libc++ -fno-exceptions -fno-rtti -c ../../src/binding.cc -o obj/deno_nosnapshot/binding.o
[2/12] touch obj/deno_nosnapshot.stamp
[3/12] TOOL_VERSION=1530535641 ../../build/toolchain/mac/linker_driver.py ../../third_party/llvm-build/Release+Asserts/bin/clang++  -stdlib=libc++ -arch x86_64 -segprot PROTECTED_MEMORY rw r -isysroot ../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -mmacosx-version-min=10.9.0 -Wl,-ObjC -o "./snapshot_creator" -Wl,-filelist,"./snapshot_creator.rsp"
[4/12] python ../../tools/run_node.py ./node_modules/typescript/bin/tsc --project ../../tsconfig.json --outDir gen/tsc_dist/
node ./node_modules/typescript/bin/tsc --project ../../tsconfig.json --outDir gen/tsc_dist/
[5/12] touch obj/run_tsc.stamp
[6/12] python ../../tools/run_node.py ./node_modules/parcel-bundler/bin/cli.js build --no-minify --out-dir gen/bundle/ ../../js/main.ts

<REDACTED>
✨  Built in 4.12s.

gen/bundle/main.js     ⚠️  6.7 MB    5.77s
gen/bundle/main.map          0 B    6.45s
node ./node_modules/parcel-bundler/bin/cli.js build --no-minify --out-dir gen/bundle/ ../../js/main.ts
[7/12] touch obj/bundle.stamp
[8/12] python ../../third_party/v8/tools/run.py /Users/Faris/Forks/deno/out/Debug/snapshot_creator gen/bundle/main.js gen/snapshot_deno.cc
[9/12] touch obj/create_snapshot_deno.stamp
[10/12] ccache ../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF obj/libdeno/from_snapshot.o.d -DV8_DEPRECATION_WARNINGS -DNO_TCMALLOC -DCHROMIUM_BUILD -DFIELDTRIAL_TESTING_ENABLED -D_LIBCPP_HAS_NO_ALIGNED_ALLOCATION -DCR_XCODE_VERSION=0941 -DCR_CLANG_REVISION=\"335864-1\" -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE=0 -D_DEBUG -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DWTF_USE_DYNAMIC_ANNOTATIONS=1 -DDEBUG -DV8_ENABLE_CHECKS -I../.. -Igen -I../../third_party/v8 -I../../third_party/v8/include -Igen/third_party/v8/include -fno-strict-aliasing -fstack-protector-strong -Wno-builtin-macro-redefined -D__DATE__= -D__TIME__= -D__TIMESTAMP__= -fcolor-diagnostics -fmerge-all-constants -Xclang -mllvm -Xclang -instcombine-lower-dbg-declare=0 -no-canonical-prefixes -arch x86_64 -Wall -Wextra -Wimplicit-fallthrough -Wthread-safety -Wunguarded-availability -Wno-missing-field-initializers -Wno-unused-parameter -Wno-c++11-narrowing -Wno-covered-switch-default -Wno-unneeded-internal-declaration -Wno-undefined-var-template -Wno-address-of-packed-member -Wno-nonportable-include-path -Wno-user-defined-warnings -Wno-unused-lambda-capture -Wno-null-pointer-arithmetic -Wno-enum-compare-switch -Wno-ignored-pragma-optimize -O0 -fno-omit-frame-pointer -g1 -isysroot ../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -mmacosx-version-min=10.9.0 -fvisibility=hidden -Wheader-hygiene -Wstring-conversion -Wtautological-overlap-compare -Wno-undefined-bool-conversion -Wno-tautological-undefined-compare -std=c++14 -stdlib=libc++ -fno-exceptions -fno-rtti -fvisibility-inlines-hidden -c ../../src/from_snapshot.cc -o obj/libdeno/from_snapshot.o
[11/12] rm -f obj/libdeno.a && TOOL_VERSION=1530535641 python ../../build/toolchain/mac/filter_libtool.py libtool -static  -o obj/libdeno.a -filelist obj/libdeno.a.rsp
[12/12] TOOL_VERSION=1530535641 ../../build/toolchain/mac/linker_driver.py ../../third_party/llvm-build/Release+Asserts/bin/clang++  -stdlib=libc++ -arch x86_64 -segprot PROTECTED_MEMORY rw r -isysroot ../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -mmacosx-version-min=10.9.0 -Wl,-ObjC -o "./deno" -Wl,-filelist,"./deno.rsp"  obj/deno_bin.o -lresolv obj/build_extra/rust/stdlib.a obj/build_extra/rust/liblibc.rlib

deno_nosnapshot build log

ninja: Entering directory `out/Debug'
[1/1] ../../third_party/v8/buildtools/mac/gn --root=../.. -q gen .
[1/7] python ../../tools/run_node.py ./node_modules/typescript/bin/tsc --project ../../tsconfig.json --outDir gen/tsc_dist/
node ./node_modules/typescript/bin/tsc --project ../../tsconfig.json --outDir gen/tsc_dist/
[2/7] touch obj/run_tsc.stamp
[3/7] python ../../tools/run_node.py ./node_modules/parcel-bundler/bin/cli.js build --no-minify --out-dir gen/bundle/ ../../js/main.ts

<REDACTED>
✨  Built in 4.00s.

gen/bundle/main.js     ⚠️  6.7 MB    5.68s
gen/bundle/main.map          0 B    6.39s
node ./node_modules/parcel-bundler/bin/cli.js build --no-minify --out-dir gen/bundle/ ../../js/main.ts
[4/7] touch obj/bundle.stamp
[5/7] ccache ../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF obj/libdeno_nosnapshot/from_filesystem.o.d -DV8_DEPRECATION_WARNINGS -DNO_TCMALLOC -DCHROMIUM_BUILD -DFIELDTRIAL_TESTING_ENABLED -D_LIBCPP_HAS_NO_ALIGNED_ALLOCATION -DCR_XCODE_VERSION=0941 -DCR_CLANG_REVISION=\"335864-1\" -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE=0 -D_DEBUG -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DWTF_USE_DYNAMIC_ANNOTATIONS=1 -DDEBUG -DV8_ENABLE_CHECKS -I../.. -Igen -I../../third_party/v8 -I../../third_party/v8/include -Igen/third_party/v8/include -fno-strict-aliasing -fstack-protector-strong -Wno-builtin-macro-redefined -D__DATE__= -D__TIME__= -D__TIMESTAMP__= -fcolor-diagnostics -fmerge-all-constants -Xclang -mllvm -Xclang -instcombine-lower-dbg-declare=0 -no-canonical-prefixes -arch x86_64 -Wall -Wextra -Wimplicit-fallthrough -Wthread-safety -Wunguarded-availability -Wno-missing-field-initializers -Wno-unused-parameter -Wno-c++11-narrowing -Wno-covered-switch-default -Wno-unneeded-internal-declaration -Wno-undefined-var-template -Wno-address-of-packed-member -Wno-nonportable-include-path -Wno-user-defined-warnings -Wno-unused-lambda-capture -Wno-null-pointer-arithmetic -Wno-enum-compare-switch -Wno-ignored-pragma-optimize -O0 -fno-omit-frame-pointer -g1 -isysroot ../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -mmacosx-version-min=10.9.0 -fvisibility=hidden -Wheader-hygiene -Wstring-conversion -Wtautological-overlap-compare -Wno-undefined-bool-conversion -Wno-tautological-undefined-compare -std=c++14 -stdlib=libc++ -fno-exceptions -fno-rtti -fvisibility-inlines-hidden -c ../../src/from_filesystem.cc -o obj/libdeno_nosnapshot/from_filesystem.o
[6/7] touch obj/libdeno_nosnapshot.stamp
[7/7] TOOL_VERSION=1530535641 ../../build/toolchain/mac/linker_driver.py ../../third_party/llvm-build/Release+Asserts/bin/clang++  -stdlib=libc++ -arch x86_64 -segprot PROTECTED_MEMORY rw r -isysroot ../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -mmacosx-version-min=10.9.0 -Wl,-ObjC -o "./deno" -Wl,-filelist,"./deno.rsp"  obj/deno_bin.o -lresolv obj/build_extra/rust/stdlib.a obj/build_extra/rust/liblibc.rlib

Footnote

Currently js_filename reference is hard coded to ./out/Debug/gen/bundle/main.js. I'm sure there is a smarter way of obtaining the bundle path.

I would gladly make the necessary changes to have this PR merged if the concept is sound, otherwise I hope this could be an inspiration for others to work on it!

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!
I haven't tested this yet, but I do think this should be a separate target. The reason is that there are situations where we would want to debug the snapshot build.
cc @mreinstein

}

Deno* NewFromFileSystem(void* data, deno_recv_cb cb) {
// TODO(f-a-a) reference this dynamically somehow?
Copy link
Member

@ry ry Jul 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One idea is to use argv[0] to locate the deno executable and try to reference the bundle relatively from there. That said, I think this is fine for a first pass.
You might try something like this in the BUILD.gn to define where the bundle file is more robustly

bl = rebase_path(get_target_outputs(":bundle")[0], root_build_dir)
define = [ "BUNDLE_LOCATION=" + bl ]

@f-a-a
Copy link
Author

f-a-a commented Jul 12, 2018

@ry PTAL!

What changed:

  • Removed is_debug condition and introduced deno_nosnapshot target that depends on libdeno_nosnapshot source_set.

  • Moved source_set definition after run_node("bundle") for get_target_ouputs(":bundle") to work.

  • I was unable to define bl as a one-liner, this error was thrown.

The thing on the left hand side of the [] must be an identifier
and not an expression. If you need this, you'll have to assign the
value to a temporary before subscripting. Sorry.
  • Reference BUNDLE_LOCATION in src/from_filesystem.cc

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

In addition to the comments below, please add deno_nosnapshot and deno_cc_nosnapshot to the travis file, to make sure we are always able to build them.

BUILD.gn Outdated
deps = [ ":libdeno" ]
}

rust_executable("deno_nosnapshot") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a deno_cc_nosnapshot too. At the moment we're using deno_cc target because rust support for flatbuffers is not complete.

Also, before the deno_nosnapshot and deno_cc_nosnapshot targets, please add some comment about their purpose. Example comment (please edit)

# This target is for fast incremental development. When modifying the javascript runtime this target will not
# go through the extra process of building a snapshot and instead load the bundle from disk.


Deno* NewFromFileSystem(void* data, deno_recv_cb cb) {
std::string js_source;
CHECK(deno::ReadFileToString(BUNDLE_LOCATION, &js_source));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For debugging purposes please add this before the ReadFileToString

printf("Reading javascript runtime bundle from " BUNDLE_LOCATION "\n");

BUILD.gn Outdated
]
configs += [ ":deno_config" ]
bt = get_target_outputs(":bundle")
bl = rebase_path(bt[0], root_build_dir)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use rebase_path(bt[0]) instead, it will set the BUNDLE_LOCATION to be an absolute path, which I think is better.

Also please use more descriptive variable names here bundle_outputs and bundle_location


std::vector<InternalFieldData*> deserialized_data;

void DeserializeInternalFields(v8::Local<v8::Object> holder, int index,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary and can be removed. There's no snapshot.

v8::Context::New(isolate, nullptr, v8::MaybeLocal<v8::ObjectTemplate>(),
v8::MaybeLocal<v8::Value>(),
v8::DeserializeInternalFieldsCallback(
DeserializeInternalFields, nullptr));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove all but the first argument to Context::New

src/handlers.rs Outdated
cmd_id,
module_specifier,
containing_file
cmd_id, module_specifier, containing_file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated change (it should have been formatted elsewhere, but it would be good if you left it out)

Copy link
Author

@f-a-a f-a-a Jul 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha, sorry about that. I'll leave this in for now yeah? (I could drop the commit though)

Edit: I dropped the commit

BUILD.gn Outdated
configs += [ ":deno_config" ]
bundle_outputs = get_target_outputs(":bundle")
bundle_location = rebase_path(bundle_outputs[0])
defines = [ "BUNDLE_LOCATION=\"${bundle_location}\"" ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think no curly braces around bundle_location

"BUNDLE_LOCATION=\"$bundle_location\""

v8::Isolate::CreateParams params;
params.array_buffer_allocator =
v8::ArrayBuffer::Allocator::NewDefaultAllocator();
params.external_references = external_references;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is unnecessary (has to do with snapshots. sorry for not catching it earlier)

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

@ry ry merged commit 7e5f0a7 into denoland:master Jul 12, 2018
@f-a-a f-a-a deleted the deno_nosnapshot branch July 12, 2018 20:01
piscisaureus pushed a commit to piscisaureus/deno that referenced this pull request Oct 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants