【问题标题】:zError function call in zLib impacting performancezLib 中的 zError 函数调用影响性能
【发布时间】:2012-01-29 11:56:56
【问题描述】:

在 iOS 项目中使用 zlib 1.25 时,我在我的分析器(Instruments)中注意到函数 zError 被重复调用,并且占用了总膨胀时间的 50%。

有谁知道为什么 zError 会被这样调用?我没有在我自己的代码中的任何地方调用它,这是一个非常样板的膨胀函数,粘贴在下面:

int UPNExtractorGZInflate(const void *src, int srcLen, void *dst, int dstLen) {
    z_stream strm  = {0};
    strm.total_in  = strm.avail_in  = srcLen;
    strm.total_out = strm.avail_out = dstLen;
    strm.next_in   = (Bytef *) src;
    strm.next_out  = (Bytef *) dst;

    strm.zalloc = Z_NULL;
    strm.zfree  = Z_NULL;
    strm.opaque = Z_NULL;

    int err = -1;
    int ret = -1;

    err = inflateInit2(&strm, (15 + 16)); //15 window bits, and the +16 tells zlib to decode gzip
    if (err == Z_OK) {
        err = inflate(&strm, Z_FINISH);
        if (err == Z_STREAM_END) {
            ret = strm.total_out;
        }
        else {
             inflateEnd(&strm);
             return err;
        }
    }
    else {
        inflateEnd(&strm);
        return err;
    }

    inflateEnd(&strm);
    return ret;
}

这是相关的分析器输出(注意 zError 占用了总膨胀时间的 50%):

【问题讨论】:

    标签: ios performance instruments zlib


    【解决方案1】:

    zError 不会被任何 zlib 函数调用。如果您没有调用它,那么您的分析器错误地识别了占用该时间的函数。

    【讨论】:

      猜你喜欢
      • 2016-05-10
      • 2015-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-30
      • 1970-01-01
      • 1970-01-01
      • 2010-09-09
      相关资源
      最近更新 更多