Kirill Kuvshinov closed issue #196: Optimize code loading by placing lambdas in big_maps at ligolang / LIGO

Kirill Kuvshinov
2021-06-27T15:03:06Z

In many cases, there is little overlap between the code used for each entrypoint. In fact, a typical pattern is to dispatch every entrypoint to a different function, though they may call common functions.

Given the high cost of deserializing and typing code, it would make sense for Michelson to support either separating the code of entrypoints or, perhaps more precisely, allowing for lazy lambdas in the storage, lambdas which are only deserialized once they are accessed.

This can be simulated in the current environment by placing lambdas inside of a big_table. One way would be to PACK the lambdas and placed them in a single big_map nat bytes for instance. However, packed lambdas are generally bad news and prevent code rewrite. Another, cleaner option, is to have one big_map per lambda with the appropriate type. The key to this big_map could be a single element, but unit is currently not comparable and can't be used as a key, leaving bool or nat as natural choices. Perhaps nat makes sense in case several lambdas happen to have the same type.

Compiling LIGO contracts to this representation would yield much smaller contracts that only load the code they need to, when they need it.