Skip to content

Fast reader writer

  • use PutUint32 to write
  • use Uint32 to read

This bypasses the whole reflection layer of the convenience binary.Read and binary.Write functions and is thus more performant.

  • updates the rw_test test file

If need be, an even more performant version could be devised with read/write functions dedicated to slices of uint32. e.g. for writing, a []byte slice corresponding to 4*len(slice) could be created in one go (where slice is the []uint32 slice), filled with binary.BigEndian.PutUint32 for each element of the []uint32 slice, and then the whole []byte slice would be written in one go (w.w.Write(data)). This would minimize the possible number of syscalls triggered by w.w.Write() (as there would be less such calls). The drawback being that one would have at some point more memory usage (memory dedicated to hold the []byte slice + the one for []uint32.) This may or may not be an issue.

Merge request reports