-
Notifications
You must be signed in to change notification settings - Fork 135
chore: use a cache for the statement parser #2790
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
Conversation
Add a cache for the statement parser that is used in the Connection API. This will reduce the number of times that a SQL string needs to be parsed by the JDBC driver and PGAdapter.
...cloud-spanner/src/main/java/com/google/cloud/spanner/connection/AbstractStatementParser.java
Outdated
Show resolved
Hide resolved
...cloud-spanner/src/main/java/com/google/cloud/spanner/connection/AbstractStatementParser.java
Outdated
Show resolved
Hide resolved
...cloud-spanner/src/main/java/com/google/cloud/spanner/connection/AbstractStatementParser.java
Outdated
Show resolved
Hide resolved
| // We do length*2 because Java uses 2 bytes for each char. | ||
| .weigher( | ||
| (Weigher<String, ParsedStatement>) | ||
| (key, value) -> 2 * key.length() + 2 * value.sqlWithoutComments.length()) |
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.
Why are we only considering value.sqlWithoutComments as there are other attributes also stored as value? Is it because those have constant small size?
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.
Yes, exactly. The other properties are all small, and all have fixed size. The statement (so the original SQL statement) is also not stored as part of the value in the cache, as that is the key that we are using.
Add a cache for the statement parser that is used in the Connection API. This will reduce the number of times that a SQL string needs to be parsed by the JDBC driver and PGAdapter.