Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix at times broken reactiveness #5

Open
Giszmo opened this issue Sep 21, 2022 · 6 comments
Open

Fix at times broken reactiveness #5

Giszmo opened this issue Sep 21, 2022 · 6 comments
Assignees

Comments

@Giszmo
Copy link
Owner

Giszmo commented Sep 21, 2022

Especially at startup, Dexie DB hooks appear to not fire, sometimes for up to 20s at a time.

The event writer reports to usually take 100ms to write 500 events and takes 100ms pauses between single-threaded writing but something is happening on that thread that makes those 100ms writes take up to 20s during which all nostroid reactivity breaks down.

My suspicion is that something CPU-intensive kicks in that slows down everything or some other DB reading/writing affects the event writer. Could it be the Garbage Collector? I certainly produce a lot of garbage all the time everywhere. This needs to be debugged. Where is the biggest potential to avoiding garbage?

@Giszmo
Copy link
Owner Author

Giszmo commented Sep 21, 2022

As the issue is very erratic - it might be one write that takes long and all before and after are smooth - I don't see how to "throttle when it gets too slow". For less powerful machines, 500 puts at a time might take too long, so maybe there is room for some mechanism that keeps the median bulkPut below 100ms but that's another issue.

@Giszmo
Copy link
Owner Author

Giszmo commented Sep 22, 2022

Apparently events get downloaded repeatedly whenever the SharedWorker starts. Observed from the relay side "53000 events were sent in 153ms", which definitely is too big a burst for the client.

@snuffyDev
Copy link
Collaborator

While investigating this I noticed a lot of the memory allocations come from Dexie. I’m also investigating what improvements, if any could be had, from using a RWLock to have a way to control the reads and writes

@snuffyDev
Copy link
Collaborator

After taking some time to ‘reset’ my brain, I’ve managed to achieve (in my opinion, after testing it for a good amount of time) a more consistent experience.

Demo: https://nostroid-test.vercel.app/

Currently preparing to commit my changes to my fork, and create a PR once I clean up a couple things and pull in the latest commits.

@snuffyDev
Copy link
Collaborator

364B2A0F-A325-477A-AC60-E93175498EBC

The heap allocations still isn’t great, which I have a few ideas on how to minimize them, but the bulk of them come from Dexie and the crypto libs it appears.

F8B9B959-4E93-4D46-B553-03BA0F7EE4C6

For reference, here’s the bar graph on this repos deployed build.

Both profiles were taken starting from the very start of the page render, to ~1-1.5 mins after it stops getting new events (around 15k)

@Giszmo
Copy link
Owner Author

Giszmo commented Oct 16, 2022

Your deployment indeed feels smoother.

The nostr library I think is part of the problem as switching it for another one had a dramatic impact on performance but that other one wasn't ready for all the features yet. It might be worth giving it another try.

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

No branches or pull requests

2 participants