NethermindEth / cairo-vm-go

A virtual machine for Cairo written in Go
MIT License
82 stars 49 forks source link

Improve `ZeroDictionary` struct #475

Closed TAdev0 closed 3 months ago

TAdev0 commented 3 months ago

This PR modifies the fields of ZeroDictionary struct to have only pointers . Because GetDictionary actually creates a copy of the dict :

// Given a memory address, it looks for the right dictionary using the segment index. If no
// segment is associated with the given segment index, it errors
func (dm *ZeroDictionaryManager) GetDictionary(dictAddr mem.MemoryAddress) (ZeroDictionary, error) {
    dict, ok := dm.Dictionaries[dictAddr.SegmentIndex]
    if ok {
        return dict, nil
    }
    return ZeroDictionary{}, fmt.Errorf("no dictionary at address: %s", dictAddr)
}

we will gain in performance in storing only an address for the whole mapping in the ZeroDictionary

TAdev0 commented 3 months ago

@har777 we discussed the fact that FreeOffset field is of type *uint64 , its actually required with our current impl of GetDictionary , as we return a copy. If i just change it for a uint64 it doesnt work anymore and any offset incrementation is done on a local copy