Data accessed faster from Dictionary than Plist?

I am making a game in SpriteKit and have been informed that it is quicker to pull data from a Dictionary than the Plist, is this true?

Every developer is looking to maintain 60fps.

Since a dictionary is already in memory and a plist has to be read form disk, that is not at all surprising. But since you can read a plist into a dictionary, I don't see the problem

1 Like

The use of "the" here ("the Plist" rather than "a Plist") has me wondering whether the question is about UserDefaults, rather than plists in general. Could you clarify which you meant? The answers are different.

Apologies for the late reply, I am between devices.

I was referring to property lists, not user defaults thanks.

I just wanted to confirm the theory. I've been looking into extracting plist values into structs (decoded) rather than into dictionaries as I have been doing, and wanted to know which course to pursue?

Conforming a class to codable and extrapolating to structs and variables is so easy (especially with some of the online JSON decoders, after converting the XML), but sorting through the data is more work than before when extracting to dictionaries and so I then wondered about speed and if it was worth the switch?

Any further thought?

It's still not clear what you're talking about. Are you talking about using PropertyListSerialization vs. PropertyListDecoder? What exactly are you trying to do? Perhaps post some sample code? And I'm not sure what any of that has to do with maintaining 60 FPS.

Sounds like you're loading data from a file and then either putting it in a dictionary or a struct and trying to decide which one of the two has better performance. I would expect performance to be roughly equal here, possibly favouring the struct in speed.

In usability and safety though, the struct would win hands down simply because you can specify types rather that having a dictionary that's defined as [String: Any] or something similar. The real performance hit is in loading the file from disk which, if I understand your question correctly, is only done once so that's not a huge deal.

Some sample code and clarification would be nice though because I'm just trying to guess what you mean at this point.

Terms of Service

Privacy Policy

Cookie Policy