Skip to content

feat(bigframes): Defer unnamed @udf deployment until needed#17217

Draft
TrevorBergeron wants to merge 2 commits into
mainfrom
tbergeron_defer_udf_create
Draft

feat(bigframes): Defer unnamed @udf deployment until needed#17217
TrevorBergeron wants to merge 2 commits into
mainfrom
tbergeron_defer_udf_create

Conversation

@TrevorBergeron
Copy link
Copy Markdown
Contributor

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements deferred deployment for unnamed User Defined Functions (UDFs) in BigFrames. Instead of provisioning UDFs immediately during registration, they are now represented as PythonUdf definitions and deployed only when the execution plan is prepared for BigQuery execution. The changes include adding tracking for deployed routines in the function session, a new plan-rewriting step in the caching executor to handle on-demand deployment, and updated data structures for UDF requirements. Feedback suggests parallelizing these deployments using asyncio.gather to improve performance when multiple UDFs are present in a single plan.

Comment on lines +551 to +557
for udf in unique_undeployed_udfs:
deployed_udf = await asyncio.to_thread(
session._function_session.deploy_undeployed_udf,
session,
udf,
)
deployed_mapping[udf] = deployed_udf
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

UDFs are currently deployed sequentially. Since each deployment involves network calls to BigQuery and resource provisioning, this can significantly delay query execution when multiple UDFs are used in a single plan. Parallelizing these deployments using asyncio.gather would improve performance.

        # Deploy UDFs in parallel to improve performance
        tasks = [
            asyncio.to_thread(
                session._function_session.deploy_undeployed_udf,
                session,
                udf,
            )
            for udf in unique_undeployed_udfs
        ]
        results = await asyncio.gather(*tasks)
        deployed_mapping = dict(zip(unique_undeployed_udfs, results))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant