Skip to content

Add generated lexer and parser #5

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

Merged
merged 1 commit into from
Apr 13, 2025
Merged

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.

1 participant