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

Performance regression in SELECT 1 #780

Open
penberg opened this issue Jan 26, 2025 · 3 comments
Open

Performance regression in SELECT 1 #780

penberg opened this issue Jan 26, 2025 · 3 comments
Labels
bug Something isn't working performance

Comments

@penberg
Copy link
Collaborator

penberg commented Jan 26, 2025

We have a large performance regression in SELECT 1, which looks to have been caused by two different points in time. The first time I can observe a regression is after #655 merge. I unfortunately am unable to pinpoint the commit as the pull request is not bisectable internally. The regression does get worse over time too, but I did not yet look into it.

@penberg penberg added bug Something isn't working performance labels Jan 26, 2025
@penberg
Copy link
Collaborator Author

penberg commented Jan 26, 2025

The problem is essentially Statement::reset() being extremely costly. I tried to bring back some performance with https://github.com/tursodatabase/limbo/actions/runs/12973129487/job/36181402243?pr=781 (which it does), but it's not complete fix because we're now not resetting the program state correctly.

As discussed with @jussisaurio, we should just have some limit (e.g. 64) of cursor and keep a single array of them in ProgramState and eliminate the hash tables at least.

@penberg
Copy link
Collaborator Author

penberg commented Jan 26, 2025

If someone want to hack on it, this (after making it work) should improve things quite a bit:

index 44d6927..c70812b 100644
--- a/core/vdbe/mod.rs
+++ b/core/vdbe/mod.rs
@@ -193,13 +193,17 @@ impl RegexCache {
     }
 }
 
+pub enum Cursor {
+    BTreeTable(BTreeCursor),
+    BTreeIndex(BTreeCursor),
+    Pseudo(PseudoCursor),
+    Sorter(Sorter),
+}
+
 /// The program state describes the environment in which the program executes.
 pub struct ProgramState {
     pub pc: InsnReference,
-    btree_table_cursors: RefCell<BTreeMap<CursorID, BTreeCursor>>,
-    btree_index_cursors: RefCell<BTreeMap<CursorID, BTreeCursor>>,
-    pseudo_cursors: RefCell<BTreeMap<CursorID, PseudoCursor>>,
-    sorter_cursors: RefCell<BTreeMap<CursorID, Sorter>>,
+    cursors: RefCell<BTreeMap<CursorID, Cursor>>,
     registers: Vec<OwnedValue>,
     last_compare: Option<std::cmp::Ordering>,
     deferred_seek: Option<(CursorID, CursorID)>,```

@jussisaurio
Copy link
Collaborator

using an array causes stack overflow. some explorations here #782

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working performance
Projects
None yet
Development

No branches or pull requests

2 participants