Skip to content

feat(bqjdbc): Add custom logger to handle ResultSet logs#13034

Open
Neenu1995 wants to merge 4 commits intomainfrom
ns/refactor-log
Open

feat(bqjdbc): Add custom logger to handle ResultSet logs#13034
Neenu1995 wants to merge 4 commits intomainfrom
ns/refactor-log

Conversation

@Neenu1995
Copy link
Copy Markdown
Contributor

@Neenu1995 Neenu1995 commented May 7, 2026

b/510827966

Optimized JDBC driver performance by implementing a custom logger for ResultSet classes, designed for low impact when logging is off and efficient handling when on.

  • Lazy Logging Overloads: Added Java 8 Supplier overloads to custom loggers, eliminating dynamic string allocations and GC pressure when logging is disabled.

  • Explicit Trace Logging: Introduced Supplier-based trace overloads (like finestTrace) with explicit method parameters, bypassing CPU-intensive stack-walking.

  • ResultSet-Wide Refactoring: Refactored 11 ResultSet-related classes to use these lazy trace overloads, removing hot-path logging overhead at the bytecode level.

  • Per-Connection Log Routing: Enhanced PerConnectionFileHandler to extract connection IDs directly from log parameters, preventing log leakage into the global log.

@Neenu1995 Neenu1995 requested review from a team as code owners May 7, 2026 18:48
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 introduces BigQueryJdbcResultSetLogger, a specialized high-performance logger designed for ResultSet and related classes to avoid expensive stack trace walking on hot paths. It updates various JDBC classes to use this new logger and its finestTrace method. Feedback highlights a potential memory leak in the logger's static cache when using connection IDs, a bug where the log method override destructively overwrites existing log parameters, and an opportunity to further optimize performance by overriding the fine logging methods.

* Log a message at Level.FINEST with predefined class name and method name to avoid stack trace
* parsing on the hot-path.
*/
public void finestTrace(String methodName, String msg) {
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.

All usages of this function are actually logging +++enter+++. Should we just replace it with finestEnter & no need to provide message or msg supplier at all?

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.

Since the RS methods don't use proxy setup, it won't know which method it called from without explicitly supplying the method name(or doing a stacktrace, which we want to avoid for perf reasons). But we can remove the ++enter++ message and have it printed here once. Which was one of the things I have planned for the next PR.

@Neenu1995 Neenu1995 requested a review from logachev May 8, 2026 21:19
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.

2 participants