status-react/project.clj

184 lines
16 KiB
Clojure
Raw Normal View History

(defproject status-im "0.1.0-SNAPSHOT"
2017-09-02 16:11:31 +00:00
:url "https://github.com/status-im/status-react/"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
;; NOTE: Dependecies here are used in CI, till the CI script will be updated
;; all deps should be maintained in deps.edn and here.
:dependencies [[org.clojure/clojure "1.10.0"]
[org.clojure/clojurescript "1.10.520"
:exclusions
[com.google.javascript/closure-compiler-unshaded
org.clojure/google-closure-library]]
;; [com.google.javascript/closure-compiler-unshaded "v20180319"]
;; v20180506
[com.google.javascript/closure-compiler-unshaded "v20190325"]
[org.clojure/google-closure-library "0.0-20190213-2033d5d9"]
[org.clojure/core.async "0.4.474"]
[reagent "0.7.0" :exclusions [cljsjs/react cljsjs/react-dom cljsjs/react-dom-server cljsjs/create-react-class]]
[re-frame "0.12.0"]
[com.andrewmcveigh/cljs-time "0.5.2"]
[status-im/timbre "4.10.0-2-status"]
[com.taoensso/encore "2.94.0"]
2017-10-19 13:58:21 +00:00
[hickory "0.7.1"]
[cljs-bean "1.3.0"]
[binaryage/oops "0.7.0"]
[mvxcvi/alphabase "1.0.0"]]
:plugins [[rasom/lein-githooks "0.1.5"]
[lein-cljsbuild "1.1.7"]
[lein-cljfmt "0.5.7"]]
:githooks {:auto-install true
:pre-commit ["lein cljfmt check src/status_im/core.cljs $(git diff --diff-filter=d --cached --name-only src test/cljs)"]}
:cljfmt {:indents {letsubs [[:inner 0]]}}
2019-06-04 15:20:03 +00:00
:clean-targets ["target/" "index.ios.js" "index.android.js" "status-modules/cljs"]
:aliases {"jsbundle" ^{:doc "Recompile code with prod profile."}
["do" "clean"
["with-profile" "prod" "cljsbuild" "once" "ios"]
["with-profile" "prod" "cljsbuild" "once" "android"]
["with-profile" "prod" "cljsbuild" "once" "desktop"]]
"jsbundle-android" ^{:doc "Recompile code for Android with prod profile."}
["do" "clean"
["with-profile" "prod" "cljsbuild" "once" "android"]]
"jsbundle-ios" ^{:doc "Recompile code for iOS with prod profile."}
["do" "clean"
["with-profile" "prod" "cljsbuild" "once" "ios"]]
"jsbundle-desktop" ^{:doc "Recompile code for desktop with prod profile."}
["do" "clean"
["with-profile" "prod" "cljsbuild" "once" "desktop"]]
"figwheel-repl" ["with-profile" "+figwheel" "run" "-m" "clojure.main" "env/dev/run.clj"]
"test-cljs" ["with-profile" "test" "doo" "node" "test" "once"]
2019-12-10 10:07:38 +00:00
"test-cljs-auto" ["with-profile" "test" "doo" "node" "test" "auto"]
"test-protocol" ["with-profile" "test" "doo" "node" "protocol" "once"]
"test-env-dev-utils" ["with-profile" "test" "doo" "node" "env-dev-utils" "once"]}
:profiles {:dev {:dependencies [[cider/piggieback "0.4.0"]]
:cljsbuild {:builds
{:ios
{:source-paths ["components/src" "react-native/src/cljsjs" "react-native/src/mobile" "src" "dev"]
:compiler {:output-to "target/ios/app.js"
:main "env.ios.main"
:output-dir "target/ios"
:optimizations :none}}
:android
{:source-paths ["components/src" "react-native/src/cljsjs" "react-native/src/mobile" "src" "dev"]
:compiler {:output-to "target/android/app.js"
:main "env.android.main"
:output-dir "target/android"
:optimizations :none}
:warning-handlers [status-im.utils.build/warning-handler]}
:desktop
{:source-paths ["components/src" "react-native/src/cljsjs" "react-native/src/desktop" "src" "dev"]
:compiler {:output-to "target/desktop/app.js"
:main "env.desktop.main"
:output-dir "target/desktop"
:optimizations :none}}}}
:repl-options {:nrepl-middleware [cider.piggieback/wrap-cljs-repl]
:timeout 240000}}
Fix message ordering and improve performance rec. messages This commit does a few things: ==== Ordering of messages ==== Change the ordering of messages from a mixture of timestamp/clock-value to use only clock-value. Datemarks are now not used for sorting anymore, which means that the order of messages is always causally related (not the case before, as we were breaking this property by sorting by datemark), but datemark calculation is unreliable (a reply to a message might have a timestamp < then the message that is replied to). So for timestamp calculation we naively group them ignoring "out-of-order timestamp" messages, although there's much to improve. It fixes an issue whereby the user would change their time and the message will be displayed in the past, although it is still possible to craft a message with a lower clock value and order it in the past (there's no way we can prevent this to some extent, but there are ways to mitigate, but outside the scope of this PR). ==== Performance of receiving messages ==== The app would freeze on pulling messages from a mailserver (100 or so). This is due to the JS Thread being hogged by CPU calculation, coupled with the fact that we always tried to process messages all in one go. This strategy can't scale, and given x is big enough (200,300,1000) the UI will freeze. Instead, each message is now processed separately, and we leave a gap between processing each message for the UI to respond to user input (otherwise the app freezes again). Pulling messages will be longer overall, but the app will be usuable while this happen (albeit it might slow down). Other strategies are possible (calculate off-db and do a big swap, avoiding many re-renders etc), but this is the reccommended strategy by re-frame author (Solving the CPU Hog problem), so sounds like a safe base point. The underlying data structure for holding messages was also changed, we used an immutable Red and Black Tree, same as a sorted map for clojure, but we use a js library as is twice as performing then clojure sorted map. We also don't sort messages again each time we receive them O(nlogn), but we insert them in order O(logn). Other data structures considered but discarded: 1) Plain vector, but performance prepending/insertion in the middle (both O(n)) were not great, as not really suited for these operations. 2) Linked list, appealing as append/prepend is O(1), while insertion is O(n). This is probably acceptable as messages tend to come in order (from the db, so adding N messages is O(n)), or the network (most of them prepends, or close to the head), while mailserver would not follow this path. An implementation of a linked list was built, which performed roughtly the same as a clojure sorted-map (although faster append/prepend), but not worth the complexity of having our own implementation. 3) Clojure sorted-map, probably the most versatile, performance were acceptable, but nowhere near the javascript implementation we decided on 4) Priority map, much slower than a sorted map (twice as slow) 5) Mutable sorted map, js implementation, (bintrees), not explored this very much, but from just a quick benchmark, performance were much worse that clojure immutable sorted map Given that each message is now processed separately, saving the chat / messages is also debounced to avoid spamming status-go with network requests. This is a temporary measure for now until that's done directly in status-go, without having to ping-pong with status-react. Next steps performance wise is to move stuff to status-go, parsing of transit, validation, which is heavy, at which point we can re-consider performance and how to handle messages. Fixes also an issue with the last message in the chat, we were using the last message in the chat list, which might not necessarely be the last message the chat has seen, in case messages were not loaded and a more recent message is the database (say you fetch historical messages for 1-to-1 A, you don't have any messages in 1-to-1 chat B loaded, you receive an historical message for chat B, it sets it as last message). Also use clj beans instead of js->clj for type conversion Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-10-24 14:23:20 +00:00
:test {:dependencies [[com.taoensso/tufte "2.1.0"]
[day8.re-frame/test "0.1.5"]]
:plugins [[lein-doo "0.1.9"]]
:cljsbuild {:builds
[{:id "test"
:source-paths ["components/src" "src" "test/cljs" "dev"]
:compiler {:main status-im.test.runner
:output-to "target/test/test.js"
:output-dir "target/test"
:optimizations :none
:preamble ["js/hook-require.js"]
:target :nodejs}}
{:id "protocol"
:source-paths ["components/src" "src" "test/cljs" "dev"]
2019-06-04 15:20:03 +00:00
:compiler {:main status-im.test.protocol.runner
:output-to "target/test/test.js"
:output-dir "target/test"
:optimizations :none
:preamble ["js/hook-require.js"]
:target :nodejs}}
{:id "env-dev-utils"
:source-paths ["env/dev/env/utils.cljs" "test/env/dev" "dev"]
:compiler {:main env.test.runner
:output-to "target/test/test.js"
:output-dir "target/test"
:optimizations :none
:target :nodejs}}]}}
:prod {:cljsbuild {:builds
{:ios
{:source-paths ["components/src" "react-native/src/cljsjs" "react-native/src/mobile" "src" "env/prod" "prod"]
2019-06-04 15:20:03 +00:00
:compiler {:main "env.ios.main"
:output-dir "target/ios-prod"
:static-fns true
:fn-invoke-direct true
:optimize-constants true
:optimizations :advanced
:pseudo-names false
:pretty-print false
:closure-defines {"goog.DEBUG" false}
:parallel-build false
:elide-asserts true
:externs ["externs.js"]
2019-06-04 15:20:03 +00:00
:language-in :es-2015
:language-out :es-2015
2019-06-08 04:04:07 +00:00
:modules {:cljs-base {:output-to "index.ios.js"}
:i18n {:entries #{"status_im.goog.i18n"}
:output-to "status-modules/cljs/i18n-raw.js"}
:network {:entries #{"status_im.network.ui.network_details.views"
"status_im.network.ui.edit_network.views"
"status_im.network.ui.edit_network.styles"
"status_im.network.ui.views"
"status_im.network.ui.styles"
"status_im.network.core"}
:output-to "status-modules/cljs/network-raw.js"}}}
:warning-handlers [status-im.utils.build/warning-handler]}
:android
{:source-paths ["components/src" "react-native/src/cljsjs" "react-native/src/mobile" "src" "env/prod" "prod"]
2019-06-04 15:20:03 +00:00
:compiler {:main "env.android.main"
:output-dir "target/android-prod"
:static-fns true
:fn-invoke-direct true
:optimize-constants true
:optimizations :advanced
:stable-names true
:pseudo-names false
:pretty-print false
:closure-defines {"goog.DEBUG" false}
:parallel-build false
:elide-asserts true
:externs ["externs.js"]
2019-06-04 15:20:03 +00:00
:language-in :es-2015
:language-out :es-2015
2019-06-08 04:04:07 +00:00
:modules {:cljs-base {:output-to "index.android.js"}
:i18n {:entries #{"status_im.goog.i18n"}
:output-to "status-modules/cljs/i18n-raw.js"}
:network {:entries #{"status_im.network.ui.network_details.views"
"status_im.network.ui.edit_network.views"
"status_im.network.ui.edit_network.styles"
"status_im.network.ui.views"
"status_im.network.ui.styles"
"status_im.network.core"}
:output-to "status-modules/cljs/network-raw.js"}}}
:warning-handlers [status-im.utils.build/warning-handler]}
:desktop
{:source-paths ["components/src" "react-native/src/cljsjs" "react-native/src/desktop" "src" "env/prod" "prod"]
2019-06-04 15:20:03 +00:00
:compiler {:main "env.desktop.main"
:output-dir "target/desktop-prod"
:static-fns true
2019-06-04 15:20:03 +00:00
:fn-invoke-direct true
:optimize-constants true
:optimizations :simple
:closure-defines {"goog.DEBUG" false}
2019-06-04 15:20:03 +00:00
:pseudo-names false
:pretty-print false
:parallel-build false
:elide-asserts true
2019-06-04 15:20:03 +00:00
:language-in :es-2015
:language-out :es-2015
2019-06-06 18:09:26 +00:00
:modules {:cljs-base {:output-to "index.desktop.js"}
:i18n {:entries #{"status_im.goog.i18n"}
:output-to "status-modules/cljs/i18n-raw.js"}
:network {:entries #{"status_im.network.ui.network_details.views"
"status_im.network.ui.edit_network.views"
"status_im.network.ui.edit_network.styles"
"status_im.network.ui.views"
"status_im.network.ui.styles"
"status_im.network.core"}
:output-to "status-modules/cljs/network-raw.js"}}}
:warning-handlers [status-im.utils.build/warning-handler]}}}}})