Zlib working extremely slow in functions

Hi! I’ve tried to add compressing with zlib to one of my functions, however i faced extremely slow performance.

Here is sample function

    exports = function(){

      const zlib = require('zlib');

      const testString = 'Test';
      const compressed = zlib.deflateSync(testString);
      return compressed;

It takes 20 seconds to complete, just to compress single word. I’ve tried another third party lib for node.js but results are pretty same. Is it known issue? Are there any ways to workaround this?

Hi @Mikhail_Mulyar

Welcome to MongoDB community!

It is possible that the overhead of loading the entire zlib package for just one function cause this latency. Can you try and load just that method?


No, it still the same. All overhead happens in deflate function. If i call it twice function will take twice longer time. So if you want to compress 4-5 words separately you easily will have timeout for this function.

Same code with much bigger string in Firebase functions takes less than a second to execute

I also have this same problem when trying to decompress GZIP data from api.

Hi @Matt_McKenzie and @Mikhail_Mulyar,

I suggest you open a case with our Support to investigate the specific slowdown in ur case.