Repository navigation
Conversation
### What problem does this PR solve? Issue Number: close apache#69918 Related PR: None Problem Summary: Nested array_map copied every visible outer lambda argument into the inner lambda block per element, including unused outer arrays, so memory was quadratic in array length. Collect only bindings the body resolves by name, and use a reserved pad column name instead of temp. ### Release note Nested array_map no longer materializes unused outer lambda arguments into each inner element, avoiding quadratic memory growth on large arrays. ### Check List (For Author) - Test: Unit Test (NestedLambdaDoesNotMaterializeUnusedOuterArgument) - Behavior changed: No (results unchanged; less memory for unused captures) - Does this need documentation: No Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
array_mapbuilds a per-element lambda block for nested lambdas. Outer lambda arguments that remain visible on theLambdaExecutionContextstack used to be copied into that block whether or not the nested body read them. SlotRefs are collected separately; name-bound lambda arguments are resolved throughresolve_column_position.What problem does this PR solve?
Issue Number: close #69918
Related PR: None
PR Type: Bug Fix
Problem Summary: A nested
array_mapcopied every visible outer lambda argument into the inner lambda block once per element, including outer arrays the body never reads. Forarray_map(x -> array_map(y -> y + 1, x), arr_of_arrays)this made memory quadratic in array length. Restrict capture to bindings the body actually resolves by name (innermost shadowing), and rename the pad column fromtempto__DORIS_LAMBDA_BLOCK_PAD__so it cannot collide with a user argument namedtemp.Details
varray_map_function.cpp,lambda_execution_context.h), ~105 lines unit test.array_mapwhose outer arguments include unused wide arrays; worse as array length grows.collect_visible_binding_column_positionsinserted every visible binding position intorequired_input_column_ids, so unused outer arrays were expanded withinsert_indices_from/clone_resizedper inner element.bind_by_name, walk the lambda body and collect onlyis_column_refnames thatresolve_column_positionfinds; keep SlotRef collection unchanged. Pad unused sparse slots with__DORIS_LAMBDA_BLOCK_PAD__.bind_by_name=falsepath unchanged.array_sorted_mergestill usescollect_visible_bindingsby name on its private block.Testing
NestedLambdaDoesNotMaterializeUnusedOuterArgument: asserts the inner lambda block has only theycolumn while still returning correcty+1results with a large unused outer array.array_mapUTs inarray_map_function_test.cppremain the regression net for referenced outer captures and shadowing (to be re-run in CIrun beut).Notes for Reviewers
Start at
ArrayMapFunction::executewhererequired_input_column_idsis built; the new helper is_collect_referenced_binding_column_positions.Release note
Nested
array_mapno longer materializes unused outer lambda arguments into each inner element, avoiding quadratic memory growth on large arrays. Query results are unchanged.Check List (For Author)
AI Disclosure