mosche commented on pull request #17172: URL: https://github.com/apache/beam/pull/17172#issuecomment-1085981280
I've drilled down into this a bit and I think I've got some interesting finding's to share @reuvenlax & @TheNeuralBit. Investigating a few approaches, I would to suggest to push field type based logic in `RowWithGetters` down into `FieldValueGetter`s to remove any branching and allow for better inlining, see [code & benchmark](https://github.com/apache/beam/compare/master...mosche:RowWithGetters-JMH-Getters-LogicPushDown). I also looked a bit into costs of caching, the picture isn't as clear there. The costs of initializing any data structure facilitating a cache is certainly high compared to the costs of calling getters. One finding though was that `TreeMap` didn't perform any worse than `HashMap`. Given the much lower memory footprint that might be a good pick then. Also, using [materialized Pojo lists](https://github.com/mosche/beam/blob/RowWithGetters-JMH-Getters-LogicPushDown/sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/GetterBasedSchemaProvider.java#L178-L180) helped to improve the performance gain from caching (compared to lazy transforms using `Lists.transform`). On the other hand, I'm not sure what the original motivation for adding a field value cache in `RowWithGetters` was. Is it just about performance? Some visualizations for a few selected runs: - [master vs suggested approach (no caching)](https://jmh.morethan.io/?sources=https://raw.githubusercontent.com/mosche/beam/RowWithGetters-JMH-Getters-LogicPushDown/sdks/java/harness/jmh/jmh-master-cache-disabled.json,https://raw.githubusercontent.com/mosche/beam/RowWithGetters-JMH-Getters-LogicPushDown/sdks/java/harness/jmh/jmh-pr-getters-cache-disabled.json) - [master vs suggested approach (with caching)](https://jmh.morethan.io/?sources=https://raw.githubusercontent.com/mosche/beam/RowWithGetters-JMH-Getters-LogicPushDown/sdks/java/harness/jmh/jmh-master-cache-HashMaps.json,https://raw.githubusercontent.com/mosche/beam/RowWithGetters-JMH-Getters-LogicPushDown/sdks/java/harness/jmh/jmh-pr-getters-cache-TreeMap-lazy-lists.json) - [costs of caching (master)](https://jmh.morethan.io/?sources=https://raw.githubusercontent.com/mosche/beam/RowWithGetters-JMH-Getters-LogicPushDown/sdks/java/harness/jmh/jmh-master-cache-disabled.json,https://raw.githubusercontent.com/mosche/beam/RowWithGetters-JMH-Getters-LogicPushDown/sdks/java/harness/jmh/jmh-master-cache-HashMaps.json) - [costs of caching (suggested approach, treemap)](https://jmh.morethan.io/?sources=https://raw.githubusercontent.com/mosche/beam/RowWithGetters-JMH-Getters-LogicPushDown/sdks/java/harness/jmh/jmh-pr-getters-cache-disabled.json,https://raw.githubusercontent.com/mosche/beam/RowWithGetters-JMH-Getters-LogicPushDown/sdks/java/harness/jmh/jmh-pr-getters-cache-TreeMap-lazy-lists.json) - [costs of caching (suggested approach, hashmap)](https://jmh.morethan.io/?sources=https://raw.githubusercontent.com/mosche/beam/RowWithGetters-JMH-Getters-LogicPushDown/sdks/java/harness/jmh/jmh-pr-getters-cache-disabled.json,https://raw.githubusercontent.com/mosche/beam/RowWithGetters-JMH-Getters-LogicPushDown/sdks/java/harness/jmh/jmh-pr-getters-cache-HashMap-lazy-lists.json) - [hashmap vs treemap if using materialized rather than lazy Pojo collections](https://jmh.morethan.io/?sources=https://raw.githubusercontent.com/mosche/beam/RowWithGetters-JMH-Getters-LogicPushDown/sdks/java/harness/jmh/jmh-pr-getters-cache-HashMap-persisted-pojolists.json,https://raw.githubusercontent.com/mosche/beam/RowWithGetters-JMH-Getters-LogicPushDown/sdks/java/harness/jmh/jmh-pr-getters-cache-TreeMap-persisted-pojolists.json) [](https://jmh.morethan.io/?sources=https://raw.githubusercontent.com/mosche/beam/RowWithGetters-JMH-Getters-LogicPushDown/sdks/java/harness/jmh/jmh-master-cache-HashMaps.json,https://raw.githubusercontent.com/mosche/beam/RowWithGetters-JMH-Getters-LogicPushDown/sdks/java/harness/jmh/jmh-pr-getters-cache-TreeMap-lazy-lists.json) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
