{"action":"created","issue":{"url":"https://api.github.com/repos/caolan/async/issues/1513","repository_url":"https://api.github.com/repos/caolan/async","labels_url":"https://api.github.com/repos/caolan/async/issues/1513/labels{/name}","comments_url":"https://api.github.com/repos/caolan/async/issues/1513/comments","events_url":"https://api.github.com/repos/caolan/async/issues/1513/events","html_url":"https://github.com/caolan/async/issues/1513","id":295583971,"number":1513,"title":"Async.waterfall is super slow. How I can optimize it?","user":{"login":"juliemobile5","id":36190368,"avatar_url":"https://avatars3.githubusercontent.com/u/36190368?v=4","gravatar_id":"","url":"https://api.github.com/users/juliemobile5","html_url":"https://github.com/juliemobile5","followers_url":"https://api.github.com/users/juliemobile5/followers","following_url":"https://api.github.com/users/juliemobile5/following{/other_user}","gists_url":"https://api.github.com/users/juliemobile5/gists{/gist_id}","starred_url":"https://api.github.com/users/juliemobile5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juliemobile5/subscriptions","organizations_url":"https://api.github.com/users/juliemobile5/orgs","repos_url":"https://api.github.com/users/juliemobile5/repos","events_url":"https://api.github.com/users/juliemobile5/events{/privacy}","received_events_url":"https://api.github.com/users/juliemobile5/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-02-08T16:44:33Z","updated_at":"2018-02-08T21:21:59Z","closed_at":null,"author_association":"NONE","body":"I am trying to implement serverless lambda function that writes text on image. However the whole function is taking on average 5 secs and sometimes up to 10 seconds to implement. I can't understand how to optimise code. \r\n\r\nHere is the editImage function which implements async.waterfall, where source image from s3 bucket is downloaded. And then it puts text on downloaded image and then uploads result to destination key.\r\n\r\n\r\n    exports.editImage = function(event, context, callback) {\r\n     // init and assign vars\r\n     async.waterfall([\r\n       async.apply(download, srcBucket, srcKey),\r\n       async.apply(editAsset, text),\r\n       async.apply(upload, dstBucket, dstKey)\r\n     ], function (err) {\r\n          if (err) console.log('Unable to transform image');\r\n         \r\n          callback(null, {statusCode: 200, body: JSON.stringify({ key: dstKey})\r\n           });\r\n         }\r\n       );\r\n    };\r\n\r\n    function download(srcBucket, srcKey, callback) {\r\n      var params = {Bucket: srcBucket, Key: srcKey};  \r\n      s3.getObject(params, callback);\r\n    };\r\n\r\n    function editAsset(text, response, callback) {\r\n       var img = gm(response.Body);\r\n       img.size(function (err, { height }){\r\n          img.drawText(0, height / 2 - 40, text.toUpperCase(), 'center');\r\n          img.toBuffer('png', function (err, buffer) {\r\n          if (err) console.log(err);\r\n          callback(null, response, buffer);\r\n       });\r\n     });\r\n    }\r\n\r\n    function upload(dstBucket, dstKey, response, buffer, callback) {\r\n      s3.putObject({\r\n          Bucket: dstBucket,\r\n          Key: dstKey,\r\n          Body: buffer,\r\n          ContentType: response.ContentType\r\n      }, function(err, data) {\r\n      if (err) {\r\n          console.log(err, err.stack);\r\n      }else{\r\n          callback(null, response, buffer);\r\n      }\r\n     });\r\n    }\r\n\r\n\r\nThe code works. But I can't understand what is causing more delays. async.waterfall or graphicsmagic operations. Can I get any advice on how to improve performance\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/caolan/async/issues/comments/364252314","html_url":"https://github.com/caolan/async/issues/1513#issuecomment-364252314","issue_url":"https://api.github.com/repos/caolan/async/issues/1513","id":364252314,"user":{"login":"ecasilla","id":4240936,"avatar_url":"https://avatars1.githubusercontent.com/u/4240936?v=4","gravatar_id":"","url":"https://api.github.com/users/ecasilla","html_url":"https://github.com/ecasilla","followers_url":"https://api.github.com/users/ecasilla/followers","following_url":"https://api.github.com/users/ecasilla/following{/other_user}","gists_url":"https://api.github.com/users/ecasilla/gists{/gist_id}","starred_url":"https://api.github.com/users/ecasilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ecasilla/subscriptions","organizations_url":"https://api.github.com/users/ecasilla/orgs","repos_url":"https://api.github.com/users/ecasilla/repos","events_url":"https://api.github.com/users/ecasilla/events{/privacy}","received_events_url":"https://api.github.com/users/ecasilla/received_events","type":"User","site_admin":false},"created_at":"2018-02-08T21:21:59Z","updated_at":"2018-02-08T21:21:59Z","author_association":"CONTRIBUTOR","body":"use `console.time` to trace which one of your function is causing the latency"}}
{"actor":{"display_login":"ecasilla"}}