[Java][FlexBuffers] Optimize Map access (#5735)

The original implementation of map access is very naive:
- Encode String to UTF8 byte[]
- Creates a new KeyVector
- Performs a binary search to find the key
- return value

So every access to the Map there was useless allocations of Keys and KeyVector
and complete encoding of the search key, which for most comparisons would be wasteful.

This changes completely removes the use of KeyVector and compute the key
positions on the spot. Besides that, it compares keys codepoint-by-codepoint,
avoiding unnecessary allocations and reducing encoding for most cases.

Some benchmarks result in a 2.75x speedup.
3 files changed
tree: cb2bbd784f3250da6acdcf7faf9facdfac885c40
  1. .appveyor/
  2. .bazelci/
  3. .github/
  4. .travis/
  5. android/
  6. CMake/
  7. conan/
  8. dart/
  9. docs/
  10. go/
  11. grpc/
  12. include/
  13. java/
  14. js/
  15. lobster/
  16. lua/
  17. net/
  18. php/
  19. python/
  20. reflection/
  21. rust/
  22. samples/
  23. snap/
  24. src/
  25. swift/
  26. tests/
  27. .clang-format
  28. .editorconfig
  29. .gitattributes
  30. .gitignore
  31. .travis.yml
  32. appveyor.yml
  33. BUILD
  34. build_defs.bzl
  35. CMakeLists.txt
  36. composer.json
  37. conanfile.py
  38. CONTRIBUTING.md
  39. LICENSE.txt
  40. package.json
  41. pom.xml
  42. readme.md
  43. WORKSPACE
readme.md

logo FlatBuffers

Build Status Build status Join the chat at https://gitter.im/google/flatbuffers Discord Chat Twitter Follow

FlatBuffers is a cross platform serialization library architected for maximum memory efficiency. It allows you to directly access serialized data without parsing/unpacking it first, while still having great forwards/backwards compatibility.

Go to our landing page to browse our documentation.

Supported operating systems

  • Windows
  • MacOS X
  • Linux
  • Android
  • And any others with a recent C++ compiler.

Supported programming languages

  • C++
  • C#
  • C
  • Dart
  • Go
  • Java
  • JavaScript
  • Lobster
  • Lua
  • PHP
  • Python
  • Rust
  • TypeScript

and more in progress...

Contribution

To contribute to this project, see CONTRIBUTING.

Licensing

Flatbuffers is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.