1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-30 16:40:57 -05:00
denoland-deno/core/libdeno/BUILD.gn
Bert Belder 41c7e96f1a
Refactor zero-copy buffers for performance and to prevent memory leaks
* In order to prevent ArrayBuffers from getting garbage collected by V8,
  we used to store a v8::Persistent<ArrayBuffer> in a map. This patch
  introduces a custom ArrayBuffer allocator which doesn't use Persistent
  handles, but instead stores a pointer to the actual ArrayBuffer data
  alongside with a reference count. Since creating Persistent handles
  has quite a bit of overhead, this change significantly increases
  performance. Various HTTP server benchmarks report about 5-10% more
  requests per second than before.

* Previously the Persistent handle that prevented garbage collection had
  to be released manually, and this wasn't always done, which was
  causing memory leaks. This has been resolved by introducing a new
  `PinnedBuf` type in both Rust and C++ that automatically re-enables
  garbage collection when it goes out of scope.

* Zero-copy buffers are now correctly wrapped in an Option if there is a
  possibility that they're not present. This clears up a correctness
  issue where we were creating zero-length slices from a null pointer,
  which is against the rules.
2019-05-01 21:11:09 +02:00

109 lines
2.3 KiB
Text

# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import("//deno.gni")
import("//third_party/v8/gni/v8.gni")
config("deno_config") {
include_dirs = [ "//third_party/v8" ] # This allows us to v8/src/base/ libraries.
configs = [ "//third_party/v8:external_config" ]
cflags = []
if (is_debug) {
defines = [ "DEBUG" ]
}
if (is_clang) {
cflags += [
"-fcolor-diagnostics",
"-fansi-escape-codes",
]
if (is_debug) {
cflags += [ "-glldb" ]
}
}
if (is_win) {
# The `/Zl` ("omit default library name") flag makes the compiler produce
# object files that can link with both the static and dynamic CRT.
cflags += [ "/Zl" ]
}
}
v8_source_set("v8") {
deps = [
"//third_party/v8:v8",
"//third_party/v8:v8_libbase",
"//third_party/v8:v8_libplatform",
"//third_party/v8:v8_libsampler",
]
configs = [ ":deno_config" ]
}
# Only functionality needed for libdeno_test and snapshot_creator
# In particular no flatbuffers, no assets, no rust, no msg handlers.
# Because snapshots are slow, it's important that snapshot_creator's
# dependencies are minimal.
v8_source_set("libdeno") {
sources = [
"api.cc",
"binding.cc",
"buffer.h",
"deno.h",
"exceptions.cc",
"exceptions.h",
"file_util.cc",
"file_util.h",
"internal.h",
"modules.cc",
]
deps = [
":v8",
]
configs = [ ":deno_config" ]
}
# The cargo-driven build links with libdeno to pull in all non-rust code.
v8_static_library("libdeno_static_lib") {
output_name = "libdeno"
deps = [
":libdeno",
"//build/config:shared_library_deps",
]
configs = [ ":deno_config" ]
}
v8_executable("snapshot_creator") {
sources = [
"snapshot_creator.cc",
]
deps = [
":libdeno",
]
configs = [ ":deno_config" ]
}
v8_executable("libdeno_test") {
testonly = true
sources = [
"file_util_test.cc",
"libdeno_test.cc",
"modules_test.cc",
"test.cc",
]
deps = [
":libdeno",
":snapshot_test",
"//testing/gtest:gtest",
]
data = [
"$target_gen_dir/snapshot_test.bin",
]
snapshot_path = rebase_path(data[0], root_build_dir)
defines = [ "SNAPSHOT_PATH=\"$snapshot_path\"" ]
configs = [ ":deno_config" ]
}
# Generates $target_gen_dir/snapshot_test.bin
snapshot("snapshot_test") {
testonly = true
source_root = "libdeno_test.js"
}