Commit Graph

16 Commits

Author SHA1 Message Date
Andrea Maria Piana c69863cda2
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-11-01 23:59:26 +01:00
Andrea Maria Piana acd7e56d1d
Add gfycat/identicon from status-go
Signed-off-by: yenda <eric@status.im>
2019-09-26 14:12:43 +02:00
yenda f538cfe848
remove web3 dependency 2019-09-12 15:51:57 +02:00
yenda 69819df39a
fix dependencies and remove js-sha3 2019-09-12 15:51:57 +02:00
yenda c3dd950286
remove realm
Signed-off-by: yenda <eric@status.im>
2019-09-09 18:40:15 +02:00
Pedro Pombeiro 58d310ffce
Remove RAM bundle support 2019-08-30 17:13:35 +02:00
Roman Volosovskyi c7c7b50281
RAM bundle basic setup 2019-05-27 17:34:17 +03:00
Andrey Shovkoplyas 5fe9e3d156
[#6587] IPFS hosted apps should not share cookies/etc
Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
2019-02-05 18:49:25 +01:00
Eric Dvorsak 21cc106ed3
cljs implementation of abi-spec
Signed-off-by: yenda <eric@status.im>
2018-09-26 21:58:14 +02:00
Aleksandr Pantiukhov eda73bf8ef
[#5583]: Stronger security checks in browser; Metamask phishing detector
Signed-off-by: Aleksandr Pantiukhov <alwxndr@gmail.com>
2018-09-18 17:54:42 +02:00
Roman Volosovskyi c61200f9ae
[#5180] Encrypt account's db with password 2018-09-13 12:20:13 +03:00
Eric Dvorsak 26b0224236
remove crypto libraries and nodeify hack
Signed-off-by: Eric Dvorsak <eric@dvorsak.fr>
2018-04-06 13:30:27 +02:00
Eric Dvorsak 0b0405d9a5
[fix #3163] remove phone command
Signed-off-by: Eric Dvorsak <eric@dvorsak.fr>
2018-02-07 15:48:53 +01:00
Roman Volosovskyi 43a5d91ca2 upgrade status-go to bugfix-updated-cht-#185-gd84d10d
changes in shh API according to https://github.com/ethereum/go-ethereum/wiki/Whisper-v5-RPC-API
2017-09-18 16:06:22 +03:00
Oskar Thorén b510488f11 fix #1050
Introduce a money namespace that solves a bunch of issues related to significant
numbers being preserved and converted correctly.
2017-08-07 13:55:22 +03:00
Roman Volosovskyi 23399c63e1 extract React Native dependencies 2017-07-17 11:38:48 +03:00