+5
Completed

AOT Collections

Lazlo Bonin (Lead Developer) 3 years ago updated 2 years ago 2

Bolt should include collections that are 100% safe with AOT platforms.

The problem right now is that generic lists and dictionaries cannot be properly stubbed for AOT, meaning they'll throw errors when they would need to be JIT compiled. For this reason, they're disabled when AOT Safe Mode is enabled and the editor is targetting an AOT platform.

There could be two approaches here:

  1. Manually stub generic lists and dictionaries of certain common types, for example List<string> or List<float>. This is simple but ultimately very limited. If you need a list of a specific class or enum, it wouldn't work in AOT.
  2. Use non-generic, non-virtual collections that are guaranteed to be AOT safe, but have the downside of being non type-safe. This means that every list or dictionary type would be supported, but these collections could contain elements of different types in the same collection (e.g. a list with both string and float items).

Currently, I'm leaning towards approach #2. It would mean introducing two new types to Bolt (or more specifically to the Ludiq framework):

  • Ludiq.AotList
  • Ludiq.AotDictionary

The list would behave exactly like an ArrayList, and the dictionary exactly like a Hashtable.

In the inspector, there would be a little additional setup step, defining the type of each item individually. It would look something like this:


Let me know if that would fit your different AOT workflows!

Finally, it's worth noting that when NOT targetting AOT, generic collections are superior in usability and performance, and ideally AOT collections should not be used.

Bolt Version:
Unity Version:
Platform(s):
Scripting Backend:
.NET Version (API Compatibility Level):
Completed

Available since 1.2.x, hoping to do something even better for the future. (Strongly typed generic collections)