7.0.1685-testing

Code Optimization

This page highlights some things you should consider while coding to optimize the memory consumption and computational complexity.

Save disk space with lower precision

The disk space consumed by individual float values can be vastly reduced by indicating the maximum accepted precision. In GreyCat we can do this using the @precision() decorator as follows:

type MyType {
    @precision(0.01)
    value: float?;
}

fn main(){
    var myFloat = 0.123456789;
    var myObject = MyType{value:myFloat};
    println(myFloat); // 0.123456789
    println(myObject.value); // 0.12
}