You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "atognolas (via GitHub)" <gi...@apache.org> on 2026/06/29 17:30:02 UTC

[PR] [IcebergIO] Cache destination Row keys in AssignDestinationsAndPartitions [beam]

atognolas opened a new pull request, #39155:
URL: https://github.com/apache/beam/pull/39155

   ## Summary
   - Add a `Map<String, Row> keyCache` in `AssignDestinationsAndPartitions.AssignDoFn` to reuse Row key objects across millions of input rows
   - Only N distinct `(destination, partition)` combinations exist (e.g. 400 for a 400-bucket table), but every row currently allocates a new Row with schema validation overhead
   - After the first N rows, all subsequent lookups are cache hits
   
   ## Motivation
   Observed during production benchmarks at scale (39M users, 400 partitions, 99-column schema). Row allocation + schema validation dominated bundle processing time unnecessarily.
   
   ## Test plan
   - [ ] Existing `AssignDestinationsAndPartitionsTest` passes
   - [ ] Run IcebergIO integration tests
   - [ ] Verify via profiling that Row allocation drops after initial cache warm-up
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
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


Re: [PR] [IcebergIO] Cache destination Row keys in AssignDestinationsAndPartitions [beam]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on PR #39155:
URL: https://github.com/apache/beam/pull/39155#issuecomment-4835283467

   ## Summary of Changes
   
   Hello, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
   
   This pull request optimizes the IcebergIO connector by caching destination and partition Row keys. By reusing these objects instead of creating new ones for every input row, the change reduces memory pressure and CPU usage during bundle processing, particularly in large-scale scenarios with many partitions.
   
   ### Highlights
   
   * **Performance Optimization**: Introduced a key cache in AssignDoFn to reuse Row objects for destination and partition combinations, significantly reducing object allocation overhead.
   * **Resource Management**: Implemented a Map-based cache that stores Row keys, preventing redundant schema validation and object creation for recurring partition paths.
   
   <details>
   <summary><b>New Features</b></summary>
   
   🧠 You can now enable **Memory** (public preview) to help **Gemini Code Assist** learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. **Click [here](https://codeassist.google/code-review/login) to enable Memory in your admin console.**
   </details>
   
   <details>
   <summary><b>Using Gemini Code Assist</b></summary>
   <br>
   
   The full guide for Gemini Code Assist can be found on our [documentation page](https://developers.google.com/gemini-code-assist/docs/review-github-code), here are some quick tips.
   
   <b>Invoking Gemini</b>
   
   You can request assistance from Gemini at any point by creating a comment using either `/gemini <command>` or `@gemini-code-assist <command>`. Below is a summary of the supported commands on the current page.
   
   Feature | Command | Description
   --- | --- | ---
   Code Review | `/gemini review` | Performs a code review for the current pull request in its current state.
   Pull Request Summary | `/gemini summary` | Provides a summary of the current pull request in its current state.
   Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments.
   Help | `/gemini help` | Displays a list of available commands.
   
   <b>Customization</b>
   
   To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a `.gemini/` folder in the base of the repository. Detailed instructions can be found [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github).
   
   <b>Limitations & Feedback</b>
   
   Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up [here](https://google.qualtrics.com/jfe/form/SV_2cyuGuTWsEw84yG).
   </details>
   
   
   [^1]: Review the [Privacy Notices](https://policies.google.com/privacy), [Generative AI Prohibited Use Policy](https://policies.google.com/terms/generative-ai/use-policy), [Terms of Service](https://policies.google.com/terms), and learn how to configure Gemini Code Assist in GitHub [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github). Gemini can make mistakes, so double check it and [use code with caution](https://support.google.com/legal/answer/13505487).
   


-- 
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


Re: [PR] [IcebergIO] Cache destination Row keys in AssignDestinationsAndPartitions [beam]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #39155: [IcebergIO] Cache destination Row keys in AssignDestinationsAndPartitions
URL: https://github.com/apache/beam/pull/39155


-- 
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


Re: [PR] [IcebergIO] Cache destination Row keys in AssignDestinationsAndPartitions [beam]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #39155:
URL: https://github.com/apache/beam/pull/39155#discussion_r3493575765


##########
sdks/java/io/iceberg/src/main/java/org/apache/beam/sdk/io/iceberg/AssignDestinationsAndPartitions.java:
##########
@@ -84,6 +84,7 @@ static class AssignDoFn extends DoFn<Row, KV<Row, Row>> {
     private transient @MonotonicNonNull Map<String, PartitionKey> partitionKeys;
     private transient @MonotonicNonNull Map<String, BeamRowWrapper> wrappers;
     private transient @MonotonicNonNull Map<String, Instant> lastRefreshTimes;
+    private transient @MonotonicNonNull Map<String, Row> keyCache;

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   Using a single flat map with a concatenated string key (`tableIdentifier + "|" + partitionPath`) requires allocating a new `String` object for every single input element, even on cache hits. Since this DoFn processes millions of rows, this overhead can be avoided by using a nested map structure: `Map<String, Map<String, Row>>`.
   
   ```suggestion
       private transient @MonotonicNonNull Map<String, Map<String, Row>> keyCache;
   ```



##########
sdks/java/io/iceberg/src/main/java/org/apache/beam/sdk/io/iceberg/AssignDestinationsAndPartitions.java:
##########
@@ -175,8 +177,13 @@ public void processElement(
 
       String partitionPath = partitionKey.toPath();
 
-      Row destAndPartition =
-          Row.withSchema(OUTPUT_SCHEMA).addValues(tableIdentifier, partitionPath).build();
+      String cacheKey = tableIdentifier + "|" + partitionPath;
+      Row destAndPartition = checkStateNotNull(keyCache).get(cacheKey);
+      if (destAndPartition == null) {
+        destAndPartition =
+            Row.withSchema(OUTPUT_SCHEMA).addValues(tableIdentifier, partitionPath).build();
+        keyCache.put(cacheKey, destAndPartition);
+      }

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   Instead of concatenating `tableIdentifier` and `partitionPath` into a new `String` on every element, use a nested map lookup. This avoids any object allocation on cache hits, which is the common case.
   
   ```java
         Map<String, Map<String, Row>> cache = checkStateNotNull(keyCache);
         Map<String, Row> tableCache = cache.get(tableIdentifier);
         if (tableCache == null) {
           tableCache = new HashMap<>();
           cache.put(tableIdentifier, tableCache);
         }
         Row destAndPartition = tableCache.get(partitionPath);
         if (destAndPartition == null) {
           destAndPartition =
               Row.withSchema(OUTPUT_SCHEMA).addValues(tableIdentifier, partitionPath).build();
           tableCache.put(partitionPath, destAndPartition);
         }
   ```



-- 
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


Re: [PR] [IcebergIO] Cache destination Row keys in AssignDestinationsAndPartitions [beam]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #39155:
URL: https://github.com/apache/beam/pull/39155#issuecomment-5664180668

   This pull request has been closed due to lack of activity. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.


-- 
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


Re: [PR] [IcebergIO] Cache destination Row keys in AssignDestinationsAndPartitions [beam]

Posted by "atognolas (via GitHub)" <gi...@apache.org>.
atognolas commented on PR #39155:
URL: https://github.com/apache/beam/pull/39155#issuecomment-4835312681

   @ahmedabu98 — Would you mind reviewing this? These are a set of IcebergIO fixes validated on production-scale benchmarks (39M users, 400 partitions, 99-column schema). The four PRs are independent and can be reviewed/merged in any order.


-- 
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


Re: [PR] [IcebergIO] Cache destination Row keys in AssignDestinationsAndPartitions [beam]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #39155:
URL: https://github.com/apache/beam/pull/39155#issuecomment-4836324887

   Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment `assign set of reviewers`


-- 
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


Re: [PR] [IcebergIO] Cache destination Row keys in AssignDestinationsAndPartitions [beam]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #39155:
URL: https://github.com/apache/beam/pull/39155#issuecomment-5570841754

   This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@beam.apache.org list. Thank you for your contributions.


-- 
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


Re: [PR] [IcebergIO] Cache destination Row keys in AssignDestinationsAndPartitions [beam]

Posted by "derrickaw (via GitHub)" <gi...@apache.org>.
derrickaw commented on PR #39155:
URL: https://github.com/apache/beam/pull/39155#issuecomment-4916327690

   Hi @atognolas, can we close this PR or any reasons to keep? Thanks


-- 
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