trading time for space in deserialization to avoid potential stack overflow