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

internal/codegen: cache pattern matching compilations #2028

Conversation

inconshreveable
Copy link
Contributor

Type overrides are checked linearly for every codegen'd type reference. That linear check currently compiles a regexp pattern for every override that's considered (multiple times, actually). This commit adds a simple memoizing cache so that each pattern is only ever compiled once. This dramatically improves performance of sqlc for users who have many overrides. ngrok's usage of sqlc generate sees a 10x speedup from this change (4s -> 0.4s).

I haven't profiled the memory tradeoff here but I expect it's negligible.

@inconshreveable inconshreveable force-pushed the inconshreveable/cache-pattern-matchers branch from a1ed2f8 to e0e5a62 Compare January 19, 2023 07:53
Type overrides are checked linearly for every codegen'd type.
That linear check currently compiles a regexp pattern for every override
that's considered. This commit adds a simple memoizing cache so that
each pattern is only ever compiled once. This dramatically improves
performance of sqlc for users who have many overrides. ngrok's usage
of sqlc generate sees a 10x speedup from this change (4s -> 0.4s).
@inconshreveable inconshreveable force-pushed the inconshreveable/cache-pattern-matchers branch from e0e5a62 to a1e2254 Compare January 19, 2023 08:12
@kyleconroy kyleconroy merged commit f1eef01 into sqlc-dev:main Jan 19, 2023
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.

None yet

2 participants