Skip to content

Conversation

@Schultzer
Copy link
Member

This PR adds a generated lexer and parser from the 2023 SQL BNF.

The initial benchmark shows a 2x improvement.

➜  sql git:(add-generated-lexer-and-parser) ✗ mix bench
Compiling 1 file (.ex)
Generated sql app
Operating System: macOS
CPU Information: Apple M1 Max
Number of Available Cores: 10
Available memory: 64 GB
Elixir 1.18.0
Erlang 27.2
JIT enabled: true

Benchmark suite executing with the following configuration:
warmup: 2 s
time: 10 s
memory time: 2 s
reduction time: 0 ns
parallel: 1
inputs: none specified
Estimated total run time: 42 s

Benchmarking inspect ...
Benchmarking to_sql ...
Benchmarking to_stirng ...
Calculating statistics...
Formatting results...

Name                ips        average  deviation         median         99th %
to_stirng          3.34      299.70 ms     ±4.44%      295.13 ms      351.28 ms
to_sql             3.33      300.31 ms     ±1.96%      299.57 ms      319.42 ms
inspect            3.26      307.21 ms     ±2.67%      304.75 ms      334.12 ms

Comparison:
to_stirng          3.34
to_sql             3.33 - 1.00x slower +0.62 ms
inspect            3.26 - 1.03x slower +7.51 ms

Memory usage statistics:

Name         Memory usage
to_stirng       222.84 MB
to_sql          223.07 MB - 1.00x memory usage +0.23 MB
inspect         227.58 MB - 1.02x memory usage +4.74 MB

**All measurements for memory usage were the same**

Additionally, interpolation is now done by double braces, which have historic presidents and aligns with Heex:

Although there does exist syntax that uses single braces:

@Schultzer Schultzer force-pushed the add-generated-lexer-and-parser branch from 10c9b77 to cab7fb3 Compare April 1, 2025 22:21
@Schultzer Schultzer force-pushed the add-generated-lexer-and-parser branch from cab7fb3 to 905b120 Compare April 13, 2025 17:52
@Schultzer Schultzer marked this pull request as ready for review April 13, 2025 17:55
@Schultzer Schultzer merged commit c145f85 into main Apr 13, 2025
1 check passed
@Schultzer Schultzer deleted the add-generated-lexer-and-parser branch April 13, 2025 18:01
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.

2 participants