Skip to content
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: Cache sql construction #522

Merged
merged 4 commits into from
Feb 14, 2024
Merged

perf: Cache sql construction #522

merged 4 commits into from
Feb 14, 2024

Conversation

patriknw
Copy link
Member

@patriknw patriknw commented Feb 9, 2024

  • avoid string concatenation and allocations
  • since they are now created each time its used due to the data partitions by slice

@johanandren can you sanity check this before I continue?

* avoid string concatenation and allocations
* since they are  now created each time its used due to the data partitions by slice
@@ -81,4 +82,29 @@ object Sql {
}
}

final class Cache {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also this mutable.Map.getOrElseUpdate from here - maybe this is more convenient, but I am not sure about the performance implications.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use immutable here since there will be no updates after initial population

Copy link
Member

@johanandren johanandren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good idea

@patriknw patriknw marked this pull request as ready for review February 13, 2024 13:18
@patriknw
Copy link
Member Author

Completed this with caching in all places (where it makes sense)

FROM $stateTable WHERE persistence_id = ?"""
}
protected def selectStateSql(slice: Int, entityType: String): String =
sqlCache.get(slice, s"selectStateSql-$entityType") {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when reviewing this, the highest risk of mistake (by me) is using the wrong cache key, such as accidentally using the same in several places

Copy link
Member

@johanandren johanandren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but way less sure it is a good idea at all after reviewing it. Esp methods that create a string with slice numbers in them in each call to avoid creating another string.

@patriknw
Copy link
Member Author

Esp methods that create a string with slice numbers in them in each call to avoid creating another string.

yeah, some might be questionable, but some might actually do much more than it looks, like those that create the slice ranges IN (0, 1, 2, ..., 255)

@johanandren
Copy link
Member

Let's merge it!

@johanandren johanandren merged commit a9d5e94 into main Feb 14, 2024
9 checks passed
@johanandren johanandren deleted the wip-sql-cache-patriknw branch February 14, 2024 16:19
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.

3 participants