How much data can be processed using params, saved and session declarations? How do these declaration affect performance and memory allocation/consumption (stack usage, data copy, etc.)? What methods can be used in case of static/dynamic arrays with 10k-100k elements?
Limitations of params, saved and session DML declarations
45 views Asked by Aleks At
1
Params
An untyped param is expanded like a macro any time it is referenced, so resource consumption depends on its use. If you have a param with a large amount of data, then it usually means that the value is a compile-time list (
[...]) with many elements, and you use a#foreachloop to process it. A#foreachloop is always unrolled, which gives long compile times and large generated code.If a param is typed in a template, then that template evaluates the param once and stores a copy in heap-allocated memory. The data is shared between all instances of the device. Cost should be negligible.
Session
Data is heap-stored, one copy per device instance.
Saved
Pretty much like data, but adds a presumably negligible small per-module cost for attribute registration.
There's two more variants of data:
Constant C tables
Creates one super-cheap module-local instance.
Independent startup memoized method
The data will be heap-allocated, initialized once, and shared across instances. Initialization is done by code, which saves size if it's easy to express the data programmatically, but can be cumbersome if it's just a table of irregular data.