pytorch
2f1ab477 - Speed up DataTypeToTypeMeta (#66113)

Commit
4 years ago
Speed up DataTypeToTypeMeta (#66113) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/66113 For a benchmark compiled in opt-mode in which the lookup items were shuffled and then the items were looked up round-robin fashion 10M times (for a total of 140M lookups) compiled in opt-mode we see: ``` Function Container Time (ms) Multiplier TypeMetaToDataType if-chain 233 1x TypeMetaToDataType std::vector 795 3.41x TypeMetaToDataType std::map 1566 6.72x TypeMetaToDataType std::unordered_map 2136 9.17x DataTypeToTypeMeta switch 102 1x DataTypeToTypeMeta std::vector 666 6.53x DataTypeToTypeMeta std::map 1212 11.9x DataTypeToTypeMeta std::unordered_map 1539 15.1x DataTypeToTypeMeta folly::F14FastMap 1789 17.5x ``` From this, we draw two conclusions: 1. Using a complex container like `std::map` is worse than using a simple vector lookup here (there aren't enough items for the Big-O to assert itself). 2. Using any container at all is a mistake. (Unless we pull in more exotic reasoning like invalidating the code cache or preventing inlining.) Test Plan: Sandcastle Reviewed By: dzhulgakov Differential Revision: D31375117 fbshipit-source-id: 0b310c6c2e94080d125c82fb7c2b43ab869adbcb
Author
Parents
Loading