Don't rebuild instances at runtime
In iTasks we have something like the following:
:: ReadResult p r w = E.sds: ReadResult !r !(sds p r w) & RWShared sds // | ...
class Identifiable sds where sdsIdentity :: ...
class Readable sds | Identifiable sds where readSDS :: ...
class Registrable sds | Readable sds where readRegisterSDS :: ...
class Writeable sds | Identifiable sds where writeSDS :: ...
class Modifiable sds | Readable, Writeable sds where modifySDS :: ...
class RWShared sds | Modifiable, Registrable sds
Because of this class structure, code to build a ReadResult
can look like this:
jsr_eval 0
buildh e_iTasks.Internal.SDS_dsdsIdentity;17 0
buildh e_iTasks.Internal.SDS_dreadSDS;18 0
buildhr e_iTasks.SDS.Definition_rReadable; 2 0
buildh e_iTasks.Internal.SDS_dreadRegisterSDS;21 0
buildhr e_iTasks.SDS.Definition_rRegistrable; 2 0
buildh e_iTasks.Internal.SDS_dsdsIdentity;17 0
buildh e_iTasks.Internal.SDS_dwriteSDS;19 0
buildhr e_iTasks.SDS.Definition_rWriteable; 2 0
buildh e_iTasks.Internal.SDS_dsdsIdentity;17 0
buildh e_iTasks.Internal.SDS_dreadSDS;18 0
buildhr e_iTasks.SDS.Definition_rReadable; 2 0
buildh e_iTasks.Internal.SDS_dmodifySDS;20 0
buildhr e_iTasks.SDS.Definition_rModifiable; 3 0
buildhr e_iTasks.SDS.Definition_rRWShared; 2 0
buildhr e_iTasks.SDS.Definition_kReadResult 3 0
This causes a high number of allocated words in these places (as well as requiring some time to generate the records): if I'm counting correctly, 13 words in total for the whole RWShared
structure. In fact the generated instance is always the same, because the function here is not overloaded. Can we not identify instances like that, and generate these in the data section, as is done with constructors with arity 0? I am looking at an example program here where well over 10% of the allocated words comes from functions like this (and I checked of course that the words allocated in those functions are mainly used for these instances).