问题
Does the --slurp option load the entire input in memory before processing it or has it been optimized somehow in order to avoid that?
回答1:
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.
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.)
来源:https://stackoverflow.com/questions/34778425/memory-usage-of-jqs-slurp-option