I wonder if it'd make sense to encode the size in the first byte or so? that way the setDocument call is cheap.