-
Notifications
You must be signed in to change notification settings - Fork 695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf: EXPOSED-204 Performance problem with getConnection() #1943
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
* | ||
* This should only hold a non-null value if [connectsViaDataSource] has been set to `true`. | ||
*/ | ||
internal var dataSourceIsolationLevel: Int? = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would try to avoid nullable fields because of boxing, but it shouldn't be a problem here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@e5l I didn't consider the implications of Int?
and boxing.
Since the goal of this PR is performance, it's an easy change to avoid the null entirely.
Please let me know if this is ok to go.
Override options include: - Using a cache of the datasource values to compare against per-transaction values - Getting the actual connection value to compare
In spite of reused connections from a connection pool instance, the lazy property initializer of a new database connection attempts to reset the transaction isolation level. This occurs regardless of whether the connection pool's set level has been overriden by a new value setting in DatabaseConfig or on the transaction itself. A flag in Database is now set if a DataSource is used to setup connections. On the first connection, this flag ensures that the level set by the DataSource is retrieved and cached. This avoids redundant resets in future connections unless the DataSource value has been overriden by DatabaseConfig or per-transaction values.
Rename new properties. Replace const integer value with a private flag that is passed from ThreadLocalTransactionManager to ThreadLocalTransaction instance. Edit tests to also check stored value in TransactionManager, in the event users access this property directly, before the data source value is retrieved and cached.
Switch unitialized Database.dataSourceIsolationLevel from nullable to -1.
27f3a01
to
1057508
Compare
In spite of reused connections from a connection pool instance, the lazy property initializer of a new database connection attempts to reset the transaction isolation level. This occurs regardless of whether the connection pool's set level has been overriden by a by a new value setting in
DatabaseConfig
or on thetransaction {}
itself.A flag in Database is now set if a
DataSource
is used to setup connections.On the first connection, this flag ensures that the level set by the DataSource is retrieved and cached. This avoids redundant resets in future connections unless the DataSource value has been overriden by
DatabaseConfig
or per-transaction values.