GithubHelp home page GithubHelp logo

isabella232 / nsuserdefaultssimulatorperformanceboost Goto Github PK

View Code? Open in Web Editor NEW

This project forked from flipboard/nsuserdefaultssimulatorperformanceboost

0.0 0.0 0.0 20 KB

Speed up reads from NSUserDefaults in the simulator

Home Page: http://engineering.flipboard.com/2015/03/nsuserdefaults-performance/

License: BSD 3-Clause "New" or "Revised" License

Objective-C 100.00%

nsuserdefaultssimulatorperformanceboost's Introduction

NSUserDefaults+SimulatorPerformance

Purpose

In iOS 8, NSUserDefaults read performance in the simulator declined significantly. For apps that read from NSUserDefaults often, this causes sluggishness while debugging and a misleading discrepancy between the real device and the simulator.

This project includes an NSUserDefaults category named NSUserDefaults+SimulatorPerformance that dramatically improves read performance in the simulator by adding a man-in-the-middle write-through cache in memory. It does so by swizzling out all of NSUserDefaults' setters and getters and replacing them with fl_-prefixed methods that correctly populate and update a cache.

Demo Project

A demo project is provided to illustrate the performance improvements this project has.

It includes three commands:

  • Write will write a set of entries into NSUserDefaults. The count of entries written is determined by the slider below.
  • Read (Slow) will read a set of entries from NSUserDefaults using the default uncached implementation of -setObject:forKey:. The count of entries read is determined by the slider below.
  • Read (Fast) will read a set of entries from NSUserDefaults using the swizzled, cached implementation of -setObject:forKey:. The count of entries read is determined by the slider below.

Note that the first time Read (Fast) is tapped it will likely have performance similar to Read (Slow) because the cached values for the entries being read aren't updated yet. On subsequent uses of the Read (Fast) button you should see significant performance gains.

Installation

Using this project is easy! All you have to do to start using it is include the NSUserDefaults+Simulator .h/.m pair in your project, that's it. This category automatically swizzles out NSUserDefaults' methods when the class is loaded if TARGET_IPHONE_SIMULATOR is on. If this is loaded, you'll see the following log at launch time.

Extensions

Important Note:

Because use of NSUserDefaults+SimulatorPerformance adds a level of indirection between you and the actual values stored in NSUserDefaults, it may cause issues when debugging extensions.

Writes from an app to an instance of NSUserDefaults that's shared with an extension will go through synchronously since the write methods in this category are write-through.

However, values written by an extension to an instance of NSUserDefaults shared with an app may be inconsistent when read by that app if a cached value exists. This is because writes to NSUserDefaults in other processes will not update the in-memory cache this category uses.

It is highly recommended that if you're going to be testing an extension that you disable this category.

License

This project is available under the BSD 3-clause license. See the LICENSE file for more info.

nsuserdefaultssimulatorperformanceboost's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.