Skip to content

Speed up account creation - #1912

Merged
link2xt merged 2 commits into
masterfrom
benchmark
Sep 14, 2020
Merged

link2xt merged 2 commits into
masterfrom
benchmark

Conversation

@link2xt

@link2xt link2xt commented Sep 14, 2020

Copy link
Copy Markdown
Collaborator

No description provided.

@link2xt

link2xt commented Sep 14, 2020

Copy link
Copy Markdown
Collaborator Author

Benchmark results for HDD:
Gnuplot

This speeds up account creation by ~50% on HDD.
Comment thread src/sql.rs
paramsv![],
)
.await?;
if !sql.table_exists("config").await?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These checks are dropped, because execute_batch should fail if some table is not created.

@link2xt

link2xt commented Sep 14, 2020

Copy link
Copy Markdown
Collaborator Author

Related benchmark PR: #1882

@flub flub left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to further split up this function so that you don't have to go through all if branches if you just created the table? I imagine we would always keep the final structure in the batch create and can thus skip all the migrations when you start from scratch.

it also means any schema changes need two code-path's to check though. i wonder if it's feasible to run the entire test-suite using both the create branch and the migration branch?

@link2xt

link2xt commented Sep 14, 2020

Copy link
Copy Markdown
Collaborator Author

Going through all the comparisons should be almost instant, it is just comparing integers in memory. I think the main problem was ALTER TABLE commands.

it also means any schema changes need two code-path's to check though. i wonder if it's feasible to run the entire test-suite using both the create branch and the migration branch?

There is no way to trigger migration path now.

It is also possible to continue adding migrations without changing execute_batch, until it is again too slow.

@r10s

r10s commented Sep 14, 2020 •

Copy link
Copy Markdown
Contributor

It is also possible to continue adding migrations without changing execute_batch, until it is again too slow.

i would also go that way, it will probably take some time until it is slow again (the summed up migrations are the result of 3 years!)

maintaining create-path and upgrade-path all the time together will easily result in overseen errors that are also hard to fix as already in the db of the users then; with the current migration-if-branches otoh we have no issues in all the years iirc.

btw, also on a mac pro ssd from 2017, performance increases by 50% - however, on another level, from 60ms to 27ms - but on cheap ssd build into cheap android phones that will probably an higher absolute win :)

@r10s

r10s commented Sep 14, 2020

Copy link
Copy Markdown
Contributor

for testing create-code-paths as well as update-code-paths: maybe we can write a test that (1) opens an "old" database file as of dbversion=0 from somewhere in the repo, (2) creates a new database, (3) checks that tables, columns, indexes in (1) and (2) are identical wrt existence. just an idea, not sure if that is really worth the effort, probably there are other tests that are more urgently missing :)

@r10s r10s left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compared all upgrade-code with the new squashed-table-creation, lgtm :)

@link2xt
link2xt merged commit 0a5d1e5 into master Sep 14, 2020
@link2xt
link2xt deleted the benchmark branch September 14, 2020 23:04
@flub

flub commented Sep 15, 2020

Copy link
Copy Markdown
Contributor

for testing create-code-paths as well as update-code-paths: maybe we can write a test that (1) opens an "old" database file as of dbversion=0 from somewhere in the repo, (2) creates a new database, (3) checks that tables, columns, indexes in (1) and (2) are identical wrt existence. just an idea, not sure if that is really worth the effort, probably there are other tests that are more urgently missing :)

I'm not sure how easy it is to do (3). I also agree that it's hard to test all corner cases. That's why my thinking was more to add a parameter which we can use in test code that forces to go the migration path. We could than add another CI run which enables this path with an env var or some other reasonable way. This way we could run the entire test suite twice, once with each db migration path.

If (3) is not that a hard problem then it this would be a much cheaper options of course.

@r10s

r10s commented Sep 15, 2020 •

Copy link
Copy Markdown
Contributor

just had a closer look on how to do (3):

we could get a single string that lists all tables and all index-creation commands using the following commands:

SELECT group_concat(name) FROM (SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name)
SELECT group_concat(sql) FROM (SELECT sql FROM sqlite_master WHERE type = 'index' ORDER BY sql)

these two strings just have to be the same on upgrade-code and create-code.

the sql-column for type=index should be identitcal, so we can use that- however, for the type=table, the sql-columns are not comparable between upgrade-code and create-code, there are different orders, spacing etc.

so, to check that also all rows are identical, we have to iterate over all tables (using similar statement as above) and build a string from all rows, using PRAGMA table_info('name') - i did not find a nice way to get all tables with all rows into a single string that can be compared then.

so, all in all, it is some work, however, probably pretty straight-forward and not hard :)

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.

3 participants