ape icon indicating copy to clipboard operation
ape copied to clipboard

Query: Add Caching Database

Open fubuloubu opened this issue 3 years ago • 4 comments
trafficstars

Overview

Ape is slow right now. We can speed it up by providing a robust caching layer.

Specification

  • [x] Create first party plugin ape_cache
  • [x] Create a database schema for types that the new query provider works with (e.g. BlockAPI, TransactionAPI)
  • [x] Override the QueryAPI.update_cache method in the new query provider plugin to serialize the query results and store them in a cache database on disk (SQLite or Postgres, should be user configurable)
  • [x] Update the QueryAPI.estimate_query and QueryAPI.perform_query to respond differently if the requested data is already available in the cache db
  • [ ] Explore what database migration commands we might need to service the database over time

Acceptance Criteria

  • [ ] Caching can be turned off/bypassed and is not a part of the critical path
  • [ ] Caching doesn't interrupt the Query Manager
  • [ ] Should always announce if functionality can't be provided
  • [ ] Should only say functionality can be done if it can completely provided
  • [ ] If functionality can be provided, the result should be exactly the same as the default query provider (brute force/default should be the same as cache)

Dependencies

#701

fubuloubu avatar Apr 04 '22 16:04 fubuloubu

ape-cache ape-cache-db

johnson2427 avatar Apr 06 '22 15:04 johnson2427

Note: do not migrate DefaultQueryProvider

fubuloubu avatar May 09 '22 22:05 fubuloubu

Just leaving a note here, some framework comparisons:

Running time <framework> -h (or the help equivalent):

time ape -h

real    0m2.962s
user    0m3.106s
sys     0m0.283s

time brownie -h

real    0m2.040s
user    0m0.838s
sys     0m0.213s

time hh --help

real    0m0.954s
user    0m0.974s
sys     0m0.148s

time forge -h

real    0m0.159s
user    0m0.005s
sys     0m0.004s

time truffle -h

real    0m1.713s
user    0m1.698s
sys     0m0.160s

PatrickAlphaC avatar Jul 02 '22 18:07 PatrickAlphaC

Just leaving a note here, some framework comparisons:

Not quite related to this feature, but yes click is overall a bit slower than what Brownie is using because it comes more "batteries included" out of the box

Eventually, the goal is rewrite a good portion of the library internals as async, and then explore using click's async implementation to help speed things up a lot.

fubuloubu avatar Jul 03 '22 04:07 fubuloubu