LZW compression?

The algorithm works by scanning through the input string for successively longer substrings until it finds one that is not in the dictionary, which is initialized to contain just the single-character strings corresponding to all the possible input characters. When such a string is found, it is added to the dictionary, and the index for the string less the last character (i.e., the longest substring that is in the dictionary) is retrieved from the dictionary and sent to output. The last input character is then used as the next starting point to scan for substrings. (per wikipedia)

The algorithm works best on data with repeated patterns, so the initial parts of a message will see little compression. As the message grows, however, the compression ratio tends asymptotically to the maximum.[1]

Uncompressed:

Compressed: