v8/test/cctest
Jaroslav Sevcik a803fad068 Make sure the identity hash is uniform (at least in the lower bits).
In the current implementation of hash code for objects (identity hash),
we do not bother to shift the hash when we retrieve it from the 
hash-length bitfield in a property array. (Even worse, we store shifted
value even if we do not have property array or inside dictionaries.)
That means that the hash-code for objects is always divisible by 1024.
Since our hash table uses a simple masking with (2^logsize - 1) to 
obtain the bucket, we get terrible hash collisions - essentially, our
hash table degenerates to a linked list for fewer than 1024 elements.

This CL always shifts the hash code so that the value in the lowest 
21 bits is uniformly distributed.

This results in big improvements on medium to large hash tables.
A program storing 1M elements into a WeakMap gets roughly
17x faster.  A program retrieving 1M elements from a Map 
improves even more dramatically (>100x).

const a = [];
for (let i = 0; i < 1e6; i++) a[i] = {};

const m = new Map();
console.time("Map.set");
for (let i = 0; i < 1e6; i++) {
  m.set(a[i], i);
}
console.timeEnd("Map.set");

console.time("Map.get");
let s = 0;
for (let i = 0; i < 1e6; i++) {
  s += m.get(a[i]);
}
console.timeEnd("Map.get");

const w = new WeakMap();
console.time("WeakMap.set");
for (let i = 0; i < 1e6; i++) {
  w.set(a[i], i);
}
console.timeEnd("WeakMap.set");

Before the fix:

Map.set: 157.575000
Map.get: 28333.182000
WeakMap.set: 6923.826000

After the fix:

Map.set: 178.382000
Map.get: 185.930000
WeakMap.set: 409.529000

Note that Map does not suffer from the hash collision on insertion because
it uses chaining (insertion into linked list is fast regardless of size!), and
we cleverly avoid lookup in the hash table on update if the key does not have 
identity hash yet. This is in contrast to the WeakMap, which uses 
open-addressing, and deals with collisions on insertion.

Bug: v8:6916
Change-Id: Ic5497bd4501e3b767b3f4acb7efb4784cbb3a2e4
Reviewed-on: https://chromium-review.googlesource.com/713616
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48480}
2017-10-12 03:47:56 +00:00
..
compiler [cctest] Record execution of parallel moves. 2017-10-11 14:18:49 +00:00
heap [heap] Introduce on-hold concurrent marking work list 2017-10-10 11:33:39 +00:00
interpreter [bigint] Support BigInts in -,~,++,-- unary ops 2017-10-12 01:40:33 +00:00
libplatform Reland "Switch tracing to use v8::TracingController" 2017-07-03 11:49:23 +00:00
libsampler Include only stuff you need, part 6: Fix cctest.h. 2016-09-01 12:02:16 +00:00
parsing [parser] Skipping inner funcs: Fix hoisting. 2017-10-05 12:00:45 +00:00
wasm [wasm] [multival] Reland: Allow function types as block types 2017-10-11 14:59:49 +00:00
BUILD.gn Remove FFI prototype. 2017-10-10 11:12:59 +00:00
cctest_exe.isolate [Swarming] Isolate perf tests. 2016-02-15 11:17:18 +00:00
cctest.cc [cctests] Check for stray Isolates in DEBUG builds 2017-10-11 13:02:15 +00:00
cctest.gyp Remove FFI prototype. 2017-10-10 11:12:59 +00:00
cctest.h [iwyu] Fix cctest inline header inclusion violation. 2017-09-08 11:59:53 +00:00
cctest.isolate [Interpreter] Refactor bytecode generator test suite. 2016-02-25 12:07:19 +00:00
cctest.status [test] Add stress_incremental_marking testing variant 2017-10-05 13:10:42 +00:00
DEPS Add DEPS files and run checkdeps in presubmit check 2014-06-03 13:39:42 +00:00
expression-type-collector-macros.h Make typing-asm match spec more closely around load/store, add more tests. 2015-11-30 21:11:47 +00:00
gay-fixed.cc Disable soon to be deprecated APIs per default for v8 2015-12-09 10:35:04 +00:00
gay-fixed.h [presubmit] Enable readability/namespace linter checking. 2015-09-30 13:47:11 +00:00
gay-precision.cc Disable soon to be deprecated APIs per default for v8 2015-12-09 10:35:04 +00:00
gay-precision.h [presubmit] Enable readability/namespace linter checking. 2015-09-30 13:47:11 +00:00
gay-shortest.cc Disable soon to be deprecated APIs per default for v8 2015-12-09 10:35:04 +00:00
gay-shortest.h [presubmit] Enable readability/namespace linter checking. 2015-09-30 13:47:11 +00:00
log-eq-of-logging-and-traversal.js Fix test-log/EquivalenceOfLoggingAndTraversal 2013-08-26 14:56:23 +00:00
OWNERS Remove x87 port 2017-07-18 18:20:40 +00:00
print-extension.cc Pass Isolate pointer to String::Utf8Value/Value constructors 2017-08-28 18:17:08 +00:00
print-extension.h Remove deprecated functions the smaller half of the remaing tests 2015-11-17 12:42:44 +00:00
profiler-extension.cc Introduce v8::CpuProfiler::New and v8::CpuProfiler::Dispose API. 2016-07-08 15:01:10 +00:00
profiler-extension.h Introduce v8::CpuProfiler::New and v8::CpuProfiler::Dispose API. 2016-07-08 15:01:10 +00:00
scope-test-helper.h [parser] Skipping inner funcs: Associate data to SharedFunctionInfo, not Script. 2017-06-30 11:12:52 +00:00
setup-isolate-for-tests.cc [heap] remove heap init from shipping binary. 2017-09-07 05:24:49 +00:00
setup-isolate-for-tests.h [heap] remove heap init from shipping binary. 2017-09-07 05:24:49 +00:00
test-access-checks.cc Fix receiver checks for v8::Function on a remote context receiver. 2017-02-22 10:13:24 +00:00
test-accessor-assembler.cc Remove ComputeFlags, simply pass in Code::Kind instead of Code::Flags 2017-09-29 15:37:27 +00:00
test-accessors.cc [cctest] Simplify the majority of callers of CcTest::CollectAllGarbage 2017-04-27 17:20:54 +00:00
test-allocation.cc [Memory] Move GetRandomMmapAddr from base::OS platform to v8::internal. 2017-09-22 15:26:18 +00:00
test-api-accessors.cc Remove experimental fast accessor builder API 2017-03-14 08:14:48 +00:00
test-api-interceptors.cc [api] Do not re-use PropertyCallbackArguments 2017-09-06 08:31:56 +00:00
test-api.cc Reland "[modules] Implement import.meta proposal" 2017-10-11 15:37:10 +00:00
test-api.h Start preparing test/cctest for jumbo compilation 2017-08-14 20:58:10 +00:00
test-array-list.cc [iwyu] Remove stale TODOs about objects-inl.h inclusion. 2017-10-09 11:14:59 +00:00
test-assembler-arm64.cc Reland "[arm64] Add slot copier to masm and use in builtins" 2017-10-11 10:38:54 +00:00
test-assembler-arm.cc [jumbo] arm unittests fixup 2017-10-03 06:24:30 +00:00
test-assembler-ia32.cc Remove ComputeFlags, simply pass in Code::Kind instead of Code::Flags 2017-09-29 15:37:27 +00:00
test-assembler-mips64.cc Remove ComputeFlags, simply pass in Code::Kind instead of Code::Flags 2017-09-29 15:37:27 +00:00
test-assembler-mips.cc Remove ComputeFlags, simply pass in Code::Kind instead of Code::Flags 2017-09-29 15:37:27 +00:00
test-assembler-ppc.cc Remove ComputeFlags, simply pass in Code::Kind instead of Code::Flags 2017-09-29 15:37:27 +00:00
test-assembler-s390.cc Remove ComputeFlags, simply pass in Code::Kind instead of Code::Flags 2017-09-29 15:37:27 +00:00
test-assembler-x64.cc Remove ComputeFlags, simply pass in Code::Kind instead of Code::Flags 2017-09-29 15:37:27 +00:00
test-atomicops.cc [cctest] Avoid disallowed "using namespace" directive. 2017-09-01 08:28:36 +00:00
test-bignum-dtoa.cc [jumbo] add test namespaces for cctest 2017-09-21 08:46:16 +00:00
test-bignum.cc [jumbo] add test namespaces for cctest 2017-09-21 08:46:16 +00:00
test-bit-vector.cc Start preparing test/cctest for jumbo compilation 2017-08-14 20:58:10 +00:00
test-circular-queue.cc Disable soon to be deprecated APIs per default for v8 2015-12-09 10:35:04 +00:00
test-code-layout.cc [iwyu] Remove stale TODOs about objects-inl.h inclusion. 2017-10-09 11:14:59 +00:00
test-code-stub-assembler.cc Add NumberAdd/NumberSub methods to CSA 2017-10-09 06:24:41 +00:00
test-code-stubs-arm64.cc [cctest] Avoid disallowed "using namespace" directive. 2017-09-01 08:28:36 +00:00
test-code-stubs-arm.cc [assembler] Remove RegisterBase::is method 2017-09-07 15:03:22 +00:00
test-code-stubs-ia32.cc [iwyu] Remove illegal inline include from "macro-assembler.h" 2017-09-13 11:44:07 +00:00
test-code-stubs-mips64.cc [iwyu] Remove illegal inline include from "macro-assembler.h" 2017-09-13 11:44:07 +00:00
test-code-stubs-mips.cc [iwyu] Remove illegal inline include from "macro-assembler.h" 2017-09-13 11:44:07 +00:00
test-code-stubs-x64.cc [jumbo] add test namespaces for cctest 2017-09-21 08:46:16 +00:00
test-code-stubs.cc [cctest] Avoid disallowed "using namespace" directive. 2017-09-01 08:28:36 +00:00
test-code-stubs.h [cctest] Avoid disallowed "using namespace" directive. 2017-09-01 08:28:36 +00:00
test-compiler.cc Use MaybeHandle for values that could be empty 2017-10-05 13:16:55 +00:00
test-constantpool.cc Start preparing test/cctest for jumbo compilation 2017-08-14 20:58:10 +00:00
test-conversions.cc [iwyu] Remove stale TODOs about objects-inl.h inclusion. 2017-10-09 11:14:59 +00:00
test-cpu-profiler.cc [profiler] Fix heap iteration to ignore deoptimized code objects. 2017-10-11 06:51:18 +00:00
test-date.cc Start preparing test/cctest for jumbo compilation 2017-08-14 20:58:10 +00:00
test-debug.cc [cleanup] Remove List. 2017-09-28 10:47:40 +00:00
test-decls.cc Start preparing test/cctest for jumbo compilation 2017-08-14 20:58:10 +00:00
test-deoptimization.cc Pass Isolate pointer to String::Utf8Value/Value constructors 2017-08-28 18:17:08 +00:00
test-dictionary.cc [runtime] Make GetHash and GetOrCreateHash member functions 2017-08-22 00:35:31 +00:00
test-disasm-arm64.cc [cctest] Avoid disallowed "using namespace" directive. 2017-09-01 08:28:36 +00:00
test-disasm-arm.cc [cctest] Avoid disallowed "using namespace" directive. 2017-09-01 08:28:36 +00:00
test-disasm-ia32.cc Remove ComputeFlags, simply pass in Code::Kind instead of Code::Flags 2017-09-29 15:37:27 +00:00
test-disasm-mips64.cc [cctest] Avoid disallowed "using namespace" directive. 2017-09-01 08:28:36 +00:00
test-disasm-mips.cc [cctest] Avoid disallowed "using namespace" directive. 2017-09-01 08:28:36 +00:00
test-disasm-ppc.cc [cctest] Avoid disallowed "using namespace" directive. 2017-09-01 08:28:36 +00:00
test-disasm-s390.cc [cctest] Avoid disallowed "using namespace" directive. 2017-09-01 08:28:36 +00:00
test-disasm-x64.cc Remove ComputeFlags, simply pass in Code::Kind instead of Code::Flags 2017-09-29 15:37:27 +00:00
test-diy-fp.cc Start preparing test/cctest for jumbo compilation 2017-08-14 20:58:10 +00:00
test-double.cc Start preparing test/cctest for jumbo compilation 2017-08-14 20:58:10 +00:00
test-dtoa.cc [jumbo] add test namespaces for cctest 2017-09-21 08:46:16 +00:00
test-elements-kind.cc [jumbo] add test namespaces for cctest 2017-09-21 08:46:16 +00:00
test-experimental-extra.js Add experimental, non-snapshotted V8 extras 2015-08-20 00:01:14 +00:00
test-extra.js Add isPromise V8 extras util 2017-04-06 13:16:35 +00:00
test-fast-dtoa.cc [jumbo] add test namespaces for cctest 2017-09-21 08:46:16 +00:00
test-feedback-vector.cc [turbofan] Optimize fast enum cache driven for..in. 2017-09-01 11:27:37 +00:00
test-feedback-vector.h [objects] Make feedback vector a first-class object 2017-07-27 13:31:55 +00:00
test-field-type-tracking.cc [jumbo] add test namespaces for cctest 2017-09-21 08:46:16 +00:00
test-fixed-dtoa.cc Start preparing test/cctest for jumbo compilation 2017-08-14 20:58:10 +00:00
test-flags.cc Start preparing test/cctest for jumbo compilation 2017-08-14 20:58:10 +00:00
test-func-name-inference.cc [iwyu] Remove include debug.h -> arguments.h 2017-02-09 09:19:23 +00:00
test-fuzz-arm64.cc [cctest] Avoid disallowed "using namespace" directive. 2017-09-01 08:28:36 +00:00
test-global-handles.cc Start preparing test/cctest for jumbo compilation 2017-08-14 20:58:10 +00:00
test-global-object.cc Pass Isolate pointer to String::Utf8Value/Value constructors 2017-08-28 18:17:08 +00:00
test-hashcode.cc [runtime] Make GetHash and GetOrCreateHash member functions 2017-08-22 00:35:31 +00:00
test-hashmap.cc [jumbo] add test source file namespace in test-hashmap.cc 2017-09-25 16:51:38 +00:00
test-heap-profiler.cc Reland "Reland "[profiler] proper observation of old space inline allocations"" 2017-09-25 15:13:01 +00:00
test-identity-map.cc [iwyu] Remove stale TODOs about objects-inl.h inclusion. 2017-10-09 11:14:59 +00:00
test-inobject-slack-tracking.cc [jumbo] add test namespaces for cctest 2017-09-21 08:46:16 +00:00
test-intl.cc [intl] Implement Intl.NumberFormat.prototype.formatToParts 2017-06-30 20:14:18 +00:00
test-javascript-arm64.cc [jumbo] arm64 cctest fixes 2017-09-30 17:17:23 +00:00
test-js-arm64-variables.cc [jumbo] arm64 cctest fixes 2017-09-30 17:17:23 +00:00
test-liveedit.cc Start preparing test/cctest for jumbo compilation 2017-08-14 20:58:10 +00:00
test-lockers.cc [jumbo] add test namespaces for cctest 2017-09-21 08:46:16 +00:00
test-log-stack-tracer.cc Start preparing test/cctest for jumbo compilation 2017-08-14 20:58:10 +00:00
test-log.cc Pass Isolate pointer to String::Utf8Value/Value constructors 2017-08-28 18:17:08 +00:00
test-macro-assembler-arm.cc [jumbo] arm unittests fixup 2017-10-03 06:24:30 +00:00
test-macro-assembler-mips64.cc Remove ComputeFlags, simply pass in Code::Kind instead of Code::Flags 2017-09-29 15:37:27 +00:00
test-macro-assembler-mips.cc Remove ComputeFlags, simply pass in Code::Kind instead of Code::Flags 2017-09-29 15:37:27 +00:00
test-macro-assembler-x64.cc [macro-assembler] Delete unused Jump/CheckBothSmi 2017-10-09 23:29:45 +00:00
test-managed.cc Refactor Managed construction 2017-09-04 11:37:42 +00:00
test-mementos.cc [iwyu] Remove stale TODOs about objects-inl.h inclusion. 2017-10-09 11:14:59 +00:00
test-modules.cc [api] Expose a module's status and exception. 2017-06-28 15:54:57 +00:00
test-object.cc [iwyu] Remove obsolete "api.h" include from "handles-inl.h". 2017-09-11 12:52:20 +00:00
test-orderedhashtable.cc [jumbo] add test namespaces for cctest 2017-09-21 08:46:16 +00:00
test-parsing.cc Parsing import.meta expression 2017-10-09 02:47:31 +00:00
test-platform-linux.cc [Memory] Move GetRandomMmapAddr from base::OS platform to v8::internal. 2017-09-22 15:26:18 +00:00
test-platform-win32.cc [Memory] Move GetRandomMmapAddr from base::OS platform to v8::internal. 2017-09-22 15:26:18 +00:00
test-platform.cc S390:Update inline asm constraint in test-platform 2016-07-16 15:36:45 +00:00
test-profile-generator.cc [jumbo] add test namespaces for cctest 2017-09-21 08:46:16 +00:00
test-random-number-generator.cc Start preparing test/cctest for jumbo compilation 2017-08-14 20:58:10 +00:00
test-regexp.cc [refactoring] Prepare conversions{.h,-inl.h,.cc} for BigInt.parseInt 2017-09-26 22:52:31 +00:00
test-representation.cc Start preparing test/cctest for jumbo compilation 2017-08-14 20:58:10 +00:00
test-run-wasm-relocation-arm64.cc Remove ComputeFlags, simply pass in Code::Kind instead of Code::Flags 2017-09-29 15:37:27 +00:00
test-run-wasm-relocation-arm.cc Remove ComputeFlags, simply pass in Code::Kind instead of Code::Flags 2017-09-29 15:37:27 +00:00
test-run-wasm-relocation-ia32.cc Remove ComputeFlags, simply pass in Code::Kind instead of Code::Flags 2017-09-29 15:37:27 +00:00
test-run-wasm-relocation-x64.cc Remove ComputeFlags, simply pass in Code::Kind instead of Code::Flags 2017-09-29 15:37:27 +00:00
test-sampler-api.cc Include only stuff you need, part 6: Fix cctest.h. 2016-09-01 12:02:16 +00:00
test-serialize.cc [serializer] Properly dispose Isolates in tests 2017-10-06 07:50:01 +00:00
test-simulator-arm64.cc [arm64-simulator] Dispose stray Isolate in test 2017-10-06 15:09:03 +00:00
test-simulator-arm.cc [arm-simulator] Dispose stray Isolate in test 2017-10-06 12:05:02 +00:00
test-strings.cc Remove --string-slices and --serialize-eager. 2017-09-28 04:41:18 +00:00
test-strtod.cc [jumbo] add test namespaces for cctest 2017-09-21 08:46:16 +00:00
test-symbols.cc [iwyu] Remove stale TODOs about objects-inl.h inclusion. 2017-10-09 11:14:59 +00:00
test-thread-termination.cc [console] correctly propagate exceptions. 2017-08-31 13:37:12 +00:00
test-threads.cc [cleanup] Replace List with std::vector in cctests and d8. 2017-08-29 13:29:26 +00:00
test-trace-event.cc [cleanup] Replace List with std::vector in cctests and d8. 2017-08-29 13:29:26 +00:00
test-traced-value.cc [tracing] Use locale independent writer for FP values. 2017-01-12 08:08:57 +00:00
test-transitions.cc [iwyu] Remove stale TODOs about objects-inl.h inclusion. 2017-10-09 11:14:59 +00:00
test-transitions.h Refactor TransitionArray access 2017-07-28 19:41:21 +00:00
test-typedarrays.cc Start preparing test/cctest for jumbo compilation 2017-08-14 20:58:10 +00:00
test-types.cc [iwyu] Remove stale TODOs about objects-inl.h inclusion. 2017-10-09 11:14:59 +00:00
test-unbound-queue.cc Disable soon to be deprecated APIs per default for v8 2015-12-09 10:35:04 +00:00
test-unboxed-doubles.cc [jumbo] add test namespaces for cctest 2017-09-21 08:46:16 +00:00
test-unscopables-hidden-prototype.cc Disable soon to be deprecated APIs per default for v8 2015-12-09 10:35:04 +00:00
test-usecounters.cc [jumbo] add test namespaces for cctest 2017-09-21 08:46:16 +00:00
test-utils-arm64.cc [assembler] Make Register et al. real classes 2017-09-06 12:13:09 +00:00
test-utils-arm64.h [assembler] Make Register et al. real classes 2017-09-06 12:13:09 +00:00
test-utils.cc Start preparing test/cctest for jumbo compilation 2017-08-14 20:58:10 +00:00
test-version.cc [build] Introduce an embedder version string 2017-10-05 07:17:45 +00:00
test-weakmaps.cc Make sure the identity hash is uniform (at least in the lower bits). 2017-10-12 03:47:56 +00:00
test-weaksets.cc [iwyu] Remove stale TODOs about objects-inl.h inclusion. 2017-10-09 11:14:59 +00:00
testcfg.py [test] Fix deterministic test shards. 2016-03-31 07:38:22 +00:00
trace-extension.cc Expose TickSample and its APIs in v8-profiler.h 2016-07-06 18:40:31 +00:00
trace-extension.h Expose TickSample and its APIs in v8-profiler.h 2016-07-06 18:40:31 +00:00
types-fuzz.h [turbofan] HeapConstant types should compare by handle address 2016-10-08 16:51:53 +00:00
unicode-helpers.h [parser/test] Move cctest/PreParserScopeAnalysis into a new file. 2017-02-07 10:11:01 +00:00