jq的--slurp选项的内存使用情况 [英] Memory usage of jq's --slurp option

查看:62
本文介绍了jq的--slurp选项的内存使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

--slurp选项是否在处理之前将整个输入加载到内存中,还是已对其进行了优化以避免这种情况?

Does the --slurp option load the entire input in memory before processing it or has it been optimized somehow in order to avoid that?

推荐答案

该问题的答案实质上是是".诸如"jq --slurp.FILE ...."之类的命令会将解析后的输入作为数组存储在内存中.与输入本身的大小相比,这通常需要更多的内存-例如,考虑将JSON对象存储为哈希表.

The answer to the question is essentially "yes". Commands such as "jq --slurp . FILE ...." store the parsed input as an array in memory. This will often require more memory than the size of the input itself -- consider for example that JSON objects are stored as hash tables.

使用jq 1.5时,通常有比输入"输入更好的替代方法.最值得注意的是,也许inputs过滤器与reduceforeach配合得很好. (如果您确实使用inputs,那么请不要忘记您可能想使用"-n"选项来调用jq.)

With jq 1.5 there are often better alternatives than "slurping" the input. Most notably, perhaps, the inputs filter works very nicely with reduce and foreach. (If you do use inputs then don't forget you will probably want to invoke jq with the "-n" option.)

这篇关于jq的--slurp选项的内存使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆