Serializing long string is very slow in tojson(). Calling tojson() takes about 15 seconds for a 16MB long string.
$ ./mongo --nodb MongoDB shell version v0.0.0 > var start = Date.now(); tojson("x".repeat(16 * 1024 * 1024)); print(Date.now() - start) 14320