You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@beam.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2022/04/01 14:37:00 UTC

[jira] [Work logged] (BEAM-14166) Improvements to RowWithGetter

     [ https://issues.apache.org/jira/browse/BEAM-14166?focusedWorklogId=751592&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-751592 ]

ASF GitHub Bot logged work on BEAM-14166:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 01/Apr/22 14:36
            Start Date: 01/Apr/22 14:36
    Worklog Time Spent: 10m 
      Work Description: 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)
   
   [![Screenshot 2022-04-01 at 14 49 46](https://user-images.githubusercontent.com/1401430/161275064-9f357215-6fb8-49a6-bb18-2c80b6bbf751.png)](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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 751592)
    Time Spent: 1h 20m  (was: 1h 10m)

> Improvements to RowWithGetter
> -----------------------------
>
>                 Key: BEAM-14166
>                 URL: https://issues.apache.org/jira/browse/BEAM-14166
>             Project: Beam
>          Issue Type: Improvement
>          Components: sdk-java-core
>            Reporter: Moritz Mack
>            Assignee: Moritz Mack
>            Priority: P2
>          Time Spent: 1h 20m
>  Remaining Estimate: 0h
>
> Various improvements to getValue(fieldIdx) in RowWithGetters mentioned [here|[https://github.com/apache/beam/pull/16947#discussion_r833602836]:]
>  * Minimize memory overhead of cache using either a index lookup (array) or a single hash map if number of fields exceeds the initial hashmap capacity
>  * The cache should be checked before calling a getter to avoid any potentially unnecessary conversion in the getter itself.
>  * [Nested rows|https://github.com/apache/beam/blob/master/sdks/java/core/src/main/java/org/apache/beam/sdk/values/RowWithGetters.java#L111] should be cached, otherwise the cache of such nested rows can't be leveraged.
>  * Handling of collections / maps / iterables can be significantly improved by simply skipping the transform in all cases where {{getValue}} for members is the [identity transform|https://github.com/apache/beam/blob/master/sdks/java/core/src/main/java/org/apache/beam/sdk/values/RowWithGetters.java#L142]. 



--
This message was sent by Atlassian Jira
(v8.20.1#820001)