Fork TupleWritable to work around its limitation, fix Mat serialization and cache the reducer input to work around java iterator limitation.