penberg / limbo

Limbo is a work-in-progress, in-process OLTP database management system, compatible with SQLite.
MIT License
960 stars 53 forks source link

Preparing a statement is slower than with SQLite #220

Open penberg opened 1 month ago

penberg commented 1 month ago
limbo/Prepare statement: 'SELECT 1'
                        time:   [1.4930 µs 1.4949 µs 1.4973 µs]
                        thrpt:  [667.86 Kelem/s 668.94 Kelem/s 669.81 Kelem/s]
                 change:
                        time:   [-1.7708% +0.2245% +1.3879%] (p = 0.84 > 0.05)
                        thrpt:  [-1.3689% -0.2240% +1.8027%]
                        No change in performance detected.

rusqlite/Prepare statement: 'SELECT 1'
                        time:   [487.04 ns 488.81 ns 491.40 ns]
                        thrpt:  [2.0350 Melem/s 2.0458 Melem/s 2.0532 Melem/s]
                 change:
                        time:   [-0.3547% +0.8598% +1.6341%] (p = 0.08 > 0.05)
                        thrpt:  [-1.6079% -0.8525% +0.3560%]
                        No change in performance detected.
Found 4 outliers among 100 measurements (4.00%)
  1 (1.00%) low mild
  2 (2.00%) high mild
  1 (1.00%) high severe
brayanjuls commented 1 month ago

This is an issue on the sqlite3_parser. I added a bench just for testing and I got this results,

code

    group.bench_function("sqlite3_parser", |b|{
        b.iter(|| {
            Parser::new("SELECT 1".as_bytes()).next();
        });
    });

results

limbo/sqlite3_parser   
                        time:   [1.2298 µs 1.2320 µs 1.2343 µs]
                        thrpt:  [810.15 Kelem/s 811.72 Kelem/s 813.15 Kelem/s]
Found 5 outliers among 100 measurements (5.00%)
  4 (4.00%) high mild
  1 (1.00%) high severe

limbo/Prepare statement: 'SELECT 1'
                        time:   [1.4111 µs 1.4178 µs 1.4263 µs]
                        thrpt:  [701.14 Kelem/s 705.29 Kelem/s 708.67 Kelem/s]
                 change:
                        time:   [-83.042% -82.895% -82.754%] (p = 0.00 < 0.05)
                        thrpt:  [+479.85% +484.62% +489.71%]
                        Performance has improved.
Found 9 outliers among 100 measurements (9.00%)
  3 (3.00%) high mild
  6 (6.00%) high severe

So the issue is in this line of code.

vivek378521 commented 1 month ago

So we replace the line with something similar in function and remove the Parser::new dependency?

penberg commented 1 month ago

I assume the Parser::new() associate function does all of the parsing so replacing that line means replacing the parser.