Skip to content

fix: EXPOSED-1071 Closing executed statements performance issue - #2907

Open
Oleg Babichev (obabichevjb) wants to merge 1 commit into
mainfrom
obabichev/exposed-1071-close-statements-perf
Open

fix: EXPOSED-1071 Closing executed statements performance issue#2907
Oleg Babichev (obabichevjb) wants to merge 1 commit into
mainfrom
obabichev/exposed-1071-close-statements-perf

Conversation

@obabichevjb

Copy link
Copy Markdown
Collaborator

Description

Summary of the change: Close executed JDBC statements in reverse order to prevent quadratic transaction cleanup time when using HikariCP.

Detailed description:

  • Why: JdbcTransaction previously closed executed statements in FIFO order. HikariCP tracks statements in a collection optimized for removal from the end, so closing a large number of accumulated statements in FIFO order caused repeated linear scans and resulted in quadratic cleanup time. This primarily affected databases reporting supportsMultipleResultSets = true, because Exposed retains their statements until transaction cleanup.

Type of Change

  • Bug fix

Affected databases:

  • MariaDB
  • Mysql5
  • Mysql8
  • Postgres
  • SqlServer

Related Issues

EXPOSED-1071 Closing executed statements performance issue

@obabichevjb

Copy link
Copy Markdown
Collaborator Author

This benchmark measures the time taken by JdbcTransaction.closeExecutedStatements() after preparing 200,000 statements in a single transaction. It compares statement cleanup before and after changing the closing order from FIFO to LIFO.

Database Multiple result sets Before After Before / after
PostgreSQL Yes 12.835 s 27.759 ms 462.39×
MariaDB Yes 12.842 s 19.833 ms 647.48×
MySQL 8 Yes 28.489 s 12.332 s 2.31×
MySQL 5 Yes 28.589 s 12.112 s 2.36×
SQLite No 363.208 µs 418.917 µs 0.87×
Oracle No 424.125 µs 367.458 µs 1.15×
H2 SQL Server mode No 348.500 µs 414.000 µs 0.84×
H2 PostgreSQL mode No 402.500 µs 369.208 µs 1.09×
H2 Oracle mode No 371.125 µs 351.208 µs 1.06×
H2 MySQL mode No 352.083 µs 370.917 µs 0.95×
H2 MariaDB mode No 386.208 µs 337.625 µs 1.14×
H2 No 367.916 µs 382.250 µs 0.96×
  • PostgreSQL cleanup decreased from 12.835 seconds to 27.759 milliseconds, a 462.39× improvement.
  • MariaDB cleanup decreased from 12.842 seconds to 19.833 milliseconds, a 647.48× improvement.
  • MySQL 5 and MySQL 8 improved by approximately 2.3×, although cleanup still took about 12 seconds.
  • Results for databases without multiple-result-set support remained in the sub-millisecond range.

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