serialize() will serialize the data it is given (if it's a reference), and if the data is large enough and the savings significant enough (and the compression code is loadable), it will compress it as well.