Commit 64d9295
committed
Optimize SQL reformatting
Add a few bits of caching:
1. Add sub-function to `parse_sql` with `lru_cache`, so that repeat calls with the same query are fast.
This saves a lot of processing in N+1 situations.
2. Cache constructed filter stacks in `get_filter_stack()`.
This avoids recreating all the various sqlparse objects for each query.
3. Pre-compile the simplification regex.
The `re` module already uses an internal LRU cache of regexes, but this avoids recompiling if the regex ever drops out of that cache.
Building on top of #1571, this takes run time for the same tested view from ~1100ms to ~950ms, another ~15% saving.1 parent 9551a7c commit 64d9295
2 files changed
+23
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
35 | 51 | | |
36 | | - | |
| 52 | + | |
37 | 53 | | |
38 | 54 | | |
39 | 55 | | |
40 | 56 | | |
41 | 57 | | |
42 | 58 | | |
43 | 59 | | |
44 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
45 | 64 | | |
46 | 65 | | |
47 | 66 | | |
48 | | - | |
49 | | - | |
50 | | - | |
| 67 | + | |
51 | 68 | | |
52 | 69 | | |
53 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
0 commit comments