Closed dghelm closed 3 years ago
Draft for option 1 at #305
Great job on option 1, that is an easy performance saving.
Can you provide an example for option 2 to help me understand it?
I think Option 2 may be better as its own function, but here's the case for it.
Lots of new devs create apps where when a user logs in for the first time, a getJSON call is made looking for their application data that doesn't exist. Then if it doesn't, there's usually something written -- possibly another 5 seconds! The user is just left watching a spinner for 5-10 seconds, but this has the potential to cut to ~3 seconds.
Right now: Reading registry entries that don't exist is very slow, but writing to rev0 is very fast. Reading registry entries that do exist is very fast, but trying to write rev0 and waiting for it to fail is very slow.
What I want to do is pass an "initializeSkylink" to a method, it will then start three parallel actions:
Now: if 1 succeeds before 2 and a skyfile is provided, a registry write at rev1 can start. (2s upload + 150 ms registry write total) if 1 succeeds before 2 and no skyfile is provided, we're done and ready for fast registry reads on future setJSONs (100ms registry write total) if 2 succeeds before 1 and a skyfile is provided, a registry write at incremented rev can start (2s upload + 150ms registry write total) if 2 succeeds before 1 and a skyfile is not provided -- data already exists so we were already prepared for future setJSONs (150ms registry read total)
We may need a different method for this, but I'd like to hear thoughts.
Closing in flavor of https://github.com/SkynetHQ/skynet-js/issues/5
Current
db.setJSON
does the following in series:[x] Option 1: The first 2 calls are very expensive and can be done in parallel. https://siasky.net/IADUtc2kNnhgWVISPvel9H_Lazb8RjOghSYFgn_mIkqcTg Finished in https://github.com/NebulousLabs/skynet-js/pull/305
[ ] Option 2: Idea needs tested, but providing a "skylink" instead of a JSON object to setJSON and getJSON. Then "initial value" skylinks can be used to try to initialize the SkyDB entry at registry rev0 without checking if the registry entry already exists or not. Also, this bypasses the first skyfile upload to save time early in the user experience and ensures that any subsequent visit to the site will not result in the registry read having to timeout.