Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,13 @@ public class BigQueryConnection extends BigQueryNoOpsConnection {

this.headerProvider = createHeaderProvider();
this.bigQuery = getBigQueryConnection();
// Fixed thread pool queues tasks to limit concurrent metadata calls and prevent API

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.

Why changing this to lazy init? Init is cheap & it won't start threads unless required

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was thinking to optimize it for the cases when connections only execute SQL statements (and never run metadata queries) so it takes absolutely zero memory or object allocations for the metadata pool.

But yeah you are right, I missed Init is cheap & it won't start threads unless required. Reverted.

// throttling.
this.metadataExecutor =
BigQueryJdbcMdc.newFixedThreadPool(
String.format("BQ-Metadata-%s", connectionId), metadataFetchThreadCount);
// Cached pool executes queries immediately without queueing and reclaims all idle threads
// when inactive, minimizing resources.
this.queryExecutor =
BigQueryJdbcMdc.newCachedThreadPool(String.format("BQ-Query-%s", connectionId));
this.metadataExecutor =
BigQueryJdbcMdc.newFixedThreadPool(
String.format("BQ-Metadata-%s", connectionId), this.metadataFetchThreadCount);
Comment on lines 365 to +371

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

To avoid unnecessary performance and memory overhead when metadata methods are not called, initialize the metadataExecutor lazily inside getMetadataExecutor() instead of eagerly in the constructor. This also avoids any potential order-of-initialization issues with this.metadataFetchThreadCount during connection construction.

References
  1. Prefer lazy initialization over eager initialization for resource-intensive objects if they are not guaranteed to be used in all execution paths, to avoid unnecessary performance and memory overhead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No

}
}

Expand Down
Loading
Loading