feat(bqjdbc): Add custom logger to handle ResultSet logs#13034
feat(bqjdbc): Add custom logger to handle ResultSet logs#13034
Conversation
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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.