commit | c42f93f2285e0d8f1ea70ccf3168200db34235f5 | [log] [tgz] |
---|---|---|
author | ulfjack <ulfjack@google.com> | Wed Jul 31 00:35:49 2019 -0700 |
committer | Copybara-Service <copybara-worker@google.com> | Wed Jul 31 00:36:56 2019 -0700 |
tree | 3a64e941ee77053942e9ed6c31b3692fba7cb2c9 | |
parent | db063a85a7196747cacf6bed44944021108a7ff8 [diff] |
Automated rollback of commit edad1182d33242b6de393aac3ace7c18090b664c. *** Reason for rollback *** After careful measurements, the original change does not seem to have the intended effect. We came to the conclusion that CompactHashMap is only an improvement over HashMap if the memory is retained across builds (i.e., not temporary during a build), or if the map is pre-sized correctly, and no iteration over entrySet() occurs. In all cases in the original change, the memory is *not* retained across builds, or the code iterates over entrySet(), making the change a net regression in total allocated memory (and therefore GC). In our use case, HashMap allocates 32 bytes per entry and 4 bytes per slot. If the HashMap has to grow its internal capacity, it reallocates the slots, effectively doubling the total allocated memory for slots. Since a hash map cannot be fully loaded, there are generally more slots than entries. Let f be the relationship between slots and entries, on average: s = f * e, with f > 1. HM = 32 * e + 4 * f * e (no reallocation) HM = 32 * e + 2 * 4 * f * e (reallocation of slots) By comparison, CompactHashMap allocates 16 bytes per entry, and 4 bytes per slot. However, when the hash map grows its internal capacity, it reallocates both the entries and the slots. CHM = 16 * e + 4 * f * e (no reallocation) CHM = 2 * 16 * e + 2 * 4 * f * e (reallocation of slots and entries) Since CHM does not allocate Map.Entry objects ahead of time, it additionally has to allocate 16 bytes per entry when iterating over the entrySet. This can be avoided by using map.forEach, which takes a two-parameter closure. This means that temporary CHM are strictly worse than Map unless we 1) preallocate the map correctly and 2) avoid iterating over the entrySet. *** Original change description *** Use CompactHashMap to reduce GC during execution PiperOrigin-RevId: 260874852
{Fast, Correct} - Choose two
Build and test software of any size, quickly and reliably.
Speed up your builds and tests: Bazel only rebuilds what is necessary. With advanced local and distributed caching, optimized dependency analysis and parallel execution, you get fast and incremental builds.
One tool, multiple languages: Build and test Java, C++, Android, iOS, Go, and a wide variety of other language platforms. Bazel runs on Windows, macOS, and Linux.
Scalable: Bazel helps you scale your organization, codebase, and continuous integration solution. It handles codebases of any size, in multiple repositories or a huge monorepo.
Extensible to your needs: Easily add support for new languages and platforms with Bazel's familiar extension language. Share and re-use language rules written by the growing Bazel community.
Follow our tutorials:
See CONTRIBUTING.md
Bazel is released in ‘Beta’. See the product roadmap to learn about the path toward a stable 1.0 release.