UIDocument & NSFileWrapper Architecture and Performance

折月煮酒 提交于 2019-11-30 13:48:06

Ok, no good news here.

We tried consulting with friends in the industry, profiling UIDocument and using modified implementations of it that alter various aspects of its operation in order to see if we can improve its performance but to no avail.

My conclusion is that UIDocument is not suitable for this kind of usage - it is just not designed to support the latency and throughput requirements we have for open operations. UIDocument should only be used when you want to open a small number of files at any given moment (much like word processors and drawing apps). Admittedly, this is exactly what Apple's documentation says, but I guess we had to learn just how serious they were the hard way :)

We ended up using some "tricks" to improve the user experience, and will move away from UIDocument as soon as we can.

So my recommendation is that only if:

  1. Your app resembles a document based app in nature, meaning you will not have more than a few documents open at any given moment
  2. You do not need the information inside the documents in order to "discover" them and show them to the user, or can afford the overhead of managing a separate index file
  3. You really need the auto saving/undo/synchronization/iCloud abilities of this class

then use it. Otherwise consider other solutions.

A a side note which is not directly related to the question but I will add here as a public service: UIDocument's async model required some major changes in the app architecture when we moved from direct file access. If you plan on making this move, evaluate the work you will need to do carefully.

Good luck future programmers.

The document classes have methods to read asynchronously. Have your tried that?

This really sounds like something more suited to Core Data or SQLite, for the metadata. At the very least, cache the metadata in Core Data (a single store for the entire app, not one per document).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!