Commit d581adb
authored
fix(bigquery-jdbc): lazy caller inference and zero-overhead coercion logging (#13365)
### Problem
When the BigQuery JDBC driver is run with JUL-to-SLF4J bridges (like
`SLF4JBridgeHandler` in Spring Boot environments), JUL's logging level
is configured to `ALL` to allow filtering to occur at the SLF4J/Logback
layer. As a result, the driver's custom logger always proceeded to log,
eagerly capturing and walking stack traces (`new
Throwable().getStackTrace()`) to find the caller class and method. On
hot paths (such as `BigQueryTypeCoercer.coerceTo` converting values for
millions of rows), this caused severe CPU and memory overhead
(representing up to ~99% CPU time in profile runs), even if SLF4J
immediately discarded the logs.
### Summary of Changes
* **Lazy Caller Inference (`BigQueryJdbcLogRecord`)**:
* Introduced `BigQueryJdbcLogRecord` (a custom subclass of `LogRecord`)
inside `BigQueryJdbcCustomLogger` to defer caller stack-trace walking
until requested by formatters/bridges.
* Ensures zero stack-walk overhead when logging is disabled under SLF4J
bridges.
* Added framework packages (like `org.slf4j.bridge.*`) to the caller
skipper list to maintain inference correctness.
* **Coercion Hot Path Optimization (`BigQueryTypeCoercer`)**:
* Switched type coercion logger to the specialized
`BigQueryJdbcResultSetLogger`.
* Replaced generic `effectiveLog.finest` with explicit context passing
using `effectiveLog.finestTrace("coerceTo", ...)`.
* Avoids stack walks entirely on the result set coercion hot path,
regardless of whether logging is enabled.
* **Unit Testing**:
* Added `testLazyCallerInference` in `BigQueryJdbcCustomLoggerTest` to
verify that stack-trace walking is deferred until queried and accurately
resolves the correct caller class/method.
### Performance Impact
* **Benchmark results**: Query execution on 100k rows × 5 cols with
high-throughput enabled yielded a **~5.9% end-to-end execution time
reduction** (and up to 3.3× speedup on larger 2M × 34 datasets where
JDBC coercion overhead is the main bottleneck).
* Eliminated millions of garbage collection allocations of
`StackTraceElement[]` on the JDBC data retrieval hot paths.1 parent 86ebaf6 commit d581adb
3 files changed
Lines changed: 102 additions & 23 deletions
File tree
- java-bigquery-jdbc/src
- main/java/com/google/cloud/bigquery/jdbc
- test/java/com/google/cloud/bigquery/jdbc
Lines changed: 72 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
56 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
57 | 113 | | |
58 | 114 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
67 | 120 | | |
68 | 121 | | |
69 | 122 | | |
| |||
Lines changed: 5 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
71 | | - | |
| 70 | + | |
| 71 | + | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
112 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
113 | 114 | | |
114 | 115 | | |
115 | 116 | | |
| |||
Lines changed: 25 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
96 | 121 | | |
97 | 122 | | |
98 | 123 | | |
| |||
0 commit comments