问题
Apple recently added support for indexeddb in both iOS8 Safari and Safari 7.1 on OSX. I am attempting to use this in a web application that stores about 65,000 records in indexeddb and queries them using some compound indexes.
It's working for me, but compared to Chrome's implementation of indexeddb, it's really, really slow.
To be specific... a query that takes 2ms against Chrome's indexeddb takes 500ms against Apple's indexedbb. This particular query is using a compound indexeddb index (2 fields in the key) using a IDBKeyRange.only value for the key to bring back about 100 documents of the 65,000 total.
My application supports websql as the storage mechanism as well and when I switch to that in Safari, performance is great. My query returns in a few ms, just like Chrome.
Anyone else having trouble with the slowness of Apple's indexeddb implementation? Any suggestions as to how to make it work better or do we just have to wait for Apple to fix it?
I believe that Apple's indexeddb implementation is actually just a wrapper on top of websql and the fact that I can implement my app using websql directly with good performance would imply that such a wrapper, if implemented well, should perform fine. Sadly, that is not yet the case!
回答1:
We have seen the same thing. A process which inserts 10000 objects takes around 5 or 6 seconds to complete on Android and 15 minutes to complete on iOS8.
Safari is a webkit browser so if it uses the same code base as this:
https://github.com/WebKit/webkit/blob/master/Source/WebKit2/DatabaseProcess/IndexedDB
then IndexedDB is (badly) based on a SQLLite database.
回答2:
I have also had that issue. But I also found that it gets slower the larger the table is. I was needing to save about 30,000 records, gotten in parts of about 2000 from the server and then inserted. Each batch insert got slower than the previous one until it took over 80minutes to insert. The solution we came up with (and it's horribly ugly) is to create a separate object store for each sync part. Then you have to deal with querying on multiple objectstores/etc. but it did make it so that it was usable.
Until apple get's their indexeddb implementation sorted out, this was the best solution I have.
来源:https://stackoverflow.com/questions/26184695/safari-implementation-of-indexeddb-is-very-slow