.riv file while it loads, including every artboard, animation, and view model instance. With deferred decoding, the runtime decodes most of these the first time you use them, so a file can be ready sooner when you only use part of it.
When to defer decoding
Deferred decoding is most useful for large files where you show only some of the artboards at a time. It moves decoding work from load time to first use:- Loading can finish sooner, because unused contents aren’t decoded.
- The first use of each deferred artboard, animation, or view model instance can take longer, because it decodes then.
- The runtime keeps a copy of the bytes for each deferred part in memory until that part decodes.
What decodes on first use
With deferred decoding on, the runtime still reads all of the file’s bytes while loading. It defers decoding of these parts:
Some parts can’t wait and decode while loading as usual.
Handling errors
With eager decoding, a malformed file fails to load. With deferred decoding, the runtime doesn’t check deferred parts while loading, so loading can succeed and errors appear on first use instead:- Creating a malformed artboard fails.
- An artboard that nests a malformed artboard loads with the nested artboard empty.
- A malformed view model instance keeps only the values read before the error.
Example usage
Deferred decoding is available in the New Runtime from v6.31.0.Enabling deferred decoding
Pass aFile.Configuration with deferDecoding set to true when you create the file. The configuration applies for the life of the file.
configuration argument defaults to File.Configuration(), which decodes eagerly.
Eager and deferred files can share a Worker. You choose the decoding mode per file. Deferred parts decode on the Worker that owns the file.
Handling artboard errors
Creating a malformed artboard withcreateArtboard(_:) throws FileError.invalidArtboard.