nicklockwood/FastCoding logo

nicklockwood/FastCoding

Free

A faster and more flexible binary file format replacement for NSCoding, Property Lists and JSON

FreeFree tier
Type
Open Source

About nicklockwood/FastCoding

FastCoder is a high-performance binary serialization format for Cocoa objects and object graphs, designed as a replacement for NSPropertyList, NSJSONSerializer, NSKeyedArchiver/Unarchiver, and Core Data. It offers faster read performance than any built-in serialization mechanism in Cocoa and faster write performance than any except JSON, while producing smaller file sizes than NSKeyedArchiver. FastCoder supports more data types than JSON or Plist, including NSURL, NSValue, NSSet, and NSOrderedSet, and allows any supported object type to be used as a dictionary key. It can automatically serialize custom classes via property inspection or via the FastCoding/NSCoding protocols. The library is thread-safe, ARC-compatible (though better performance with ARC disabled), and includes buffer overflow protection for security. It supports iOS 9.0+/macOS 10.10+ and is open source under a permissive license.

Key Features

High-performance binary serialization for Cocoa objects and object graphs
Faster read performance than all built-in Cocoa serialization mechanisms
Faster write performance than any mechanism except JSON
Smaller file size than NSKeyedArchiver, comparable to other methods
Supports more data types than JSON or Plist: NSURL, NSValue, NSSet, NSOrderedSet, and any object as dictionary key
Automatic serialization of custom classes using property inspection
Can also serialize via FastCoding or NSCoding protocols
Thread-safe: concurrent encoding and decoding from multiple threads
Buffer overflow protection to prevent code injection attacks
ARC-compatible (better performance with ARC disabled)

Pros & Cons

Pros
  • Faster read performance than NSCoding, NSPropertyList, and NSJSONSerializer
  • Supports a wider range of data types than JSON or Plist
  • Automatic serialization of custom classes reduces boilerplate code
  • Thread-safe and secure against buffer overflow attacks
  • Free and open source with a permissive license
  • Easy to integrate without additional dependencies or setup
Cons
  • Best performance requires disabling ARC on FastCoder.m (requires compiler flag)
  • Not recommended for loading arbitrary files from untrusted sources due to potential class injection risk
  • Limited to Cocoa platforms (iOS/macOS/tvOS/watchOS) due to Objective-C dependency
  • Write performance still slower than JSON, which may be preferred for simple data types

Best For

Replacing NSKeyedArchiver/Unarchiver for faster object serialization in iOS/macOS appsStoring complex object graphs with more data types than JSON or Plist allowPersisting custom class instances without manual encoding via property inspectionHigh-performance caching or networking serialization where speed is criticalServing as a lightweight alternative to Core Data for simple object persistence

FAQ

What is FastCoder?
FastCoder is a high-performance binary serialization format for Cocoa objects and object graphs, intended as a replacement for NSPropertyList, NSJSONSerializer, NSKeyedArchiver/Unarchiver, and Core Data.
What platforms does FastCoder support?
FastCoder supports iOS 9.0+ and macOS 10.10+ as the earliest deployment targets, and is compatible back to iOS 4.0 and macOS 10.6.
How do I install FastCoder?
Simply drag the FastCoder.h and FastCoder.m files into your Xcode project.
Is FastCoder thread-safe?
Yes, it is safe to call FastCoder encoding and decoding class methods concurrently from multiple threads, provided you do not mutate the object while it is being encoded.
How does FastCoder handle security?
FastCoder checks for buffer overflow errors during parsing and throws an exception if data instructs reading past the end. It prevents code injection, but loading arbitrary FastCoded files from untrusted sources may still pose a class creation risk.
Can FastCoder serialize custom classes automatically?
Yes, FastCoder can automatically serialize custom classes using property inspection. If that doesn't work, you can implement the FastCoding or NSCoding protocols.