Skip to content

Experimenting with DataScript performance for re-frame.

License

Notifications You must be signed in to change notification settings

day8/re-datascript-benchmark-experiments

Repository files navigation

re-datascript-bench

A re-frame application that does basic measurements of DataScript performance.

Re-runs all measurements with both:

  • number of entities 100, 1000, 10,000 and 100,000
  • entities with 1, 2 and 3 attributes

Includes the following measurements:

  • insert times (d/transact!)
  • datalog query times (d/q)
  • pull query times (q/pull)
  • transit serialisation of entire db (datascript-transit)
  • transit deserialisation of entire db ((datascript-transit))

Observations

In Google Chrome on an AMD Ryzen 5000-series desktop:

  • insert times range from 16ms for 100 single attribute entities to 7.2s for 100K triple attribute entities
  • query times on the same range from 0.3ms to 145ms
  • transit serialisation ranges from 0.7ms to 560ms
  • transit deserialisation ranges from 0.8ms to 770ms

So DataScript itself is not terrible, but the posh query analyzer and cache layer on top of DataScript is known to have pathological performance cases.

Useful DataScript Resources

Alternatives

Getting Started

Environment Setup

  1. Install JDK 8 or later (Java Development Kit)
  2. Install Leiningen (Clojure/ClojureScript project task & dependency management)
  3. Install Node.js (JavaScript runtime environment) which should include NPM or if your Node.js installation does not include NPM also install it.
  4. Clone this repo and open a terminal in the re-datascript-bench project root directory
  5. (Optional) Download project dependencies:
    lein deps

Development

Running the App

Start a temporary local web server, build the app with the dev profile, and serve the app, browser test runner and karma test runner with hot reload:

lein watch

Please be patient; it may take over 20 seconds to see any output, and over 40 seconds to complete.

When [:app] Build completed appears in the output, browse to http://localhost:8280/.

shadow-cljs will automatically push ClojureScript code changes to your browser on save. To prevent a few common issues, see Hot Reload in ClojureScript: Things to avoid.

Opening the app in your browser starts a ClojureScript browser REPL, to which you may now connect.

Connecting to the browser REPL from your editor

See Shadow CLJS User's Guide: Editor Integration. Note that lein watch runs shadow-cljs watch for you, and that this project's running build ids is app, browser-test, karma-test, or the keywords :app, :browser-test, :karma-test in a Clojure context.

Alternatively, search the web for info on connecting to a shadow-cljs ClojureScript browser REPL from your editor and configuration.

For example, in Vim / Neovim with fireplace.vim

  1. Open a .cljs file in the project to activate fireplace.vim
  2. In normal mode, execute the Piggieback command with this project's running build id, :app:
    :Piggieback :app

Connecting to the browser REPL from a terminal

  1. Connect to the shadow-cljs nREPL:

    lein repl :connect localhost:8777

    The REPL prompt, shadow.user=>, indicates that is a Clojure REPL, not ClojureScript.

  2. In the REPL, switch the session to this project's running build id, :app:

    (shadow.cljs.devtools.api/nrepl-select :app)

    The REPL prompt changes to cljs.user=>, indicating that this is now a ClojureScript REPL.

  3. See user.cljs for symbols that are immediately accessible in the REPL without needing to require.

Running shadow-cljs Actions

See a list of shadow-cljs CLI actions:

lein run -m shadow.cljs.devtools.cli --help

Please be patient; it may take over 10 seconds to see any output. Also note that some actions shown may not actually be supported, outputting "Unknown action." when run.

Run a shadow-cljs action on this project's build id (without the colon, just app):

lein run -m shadow.cljs.devtools.cli <action> app

License

The MIT License (MIT)

Copyright © 2021 Isaac Johnston

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Experimenting with DataScript performance for re-frame.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published