weixin_39713814
weixin_39713814
2020-11-30 04:52

ExecuteBuffer for that case if you already know the size of your result

ExecuteBuffer for that case if you already know the size of your rendered template. In some cases it can save up to 28% of execution time.

该提问来源于开源项目:flosch/pongo2

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

8条回答

  • weixin_39834084 weixin_39834084 5月前

    Please pull the latest changes from my master when you've finished editing your pull request.

    点赞 评论 复制链接分享
  • weixin_39713814 weixin_39713814 5月前

    Oh sorry, I did not know that I still able to commit to this pull request. Now I am done ;)

    点赞 评论 复制链接分享
  • weixin_39834084 weixin_39834084 5月前

    Thanks, I've merged this.

    点赞 评论 复制链接分享
  • weixin_39834084 weixin_39834084 5月前

    However, after thinking about it it might be redundant with ExecuteWriter(). Maybe I change some of the internals to allow use ExecuteWriter() for such situations and to prevent any buffer allocation. Would be the preferred way to go I believe because it would speed up almost any template generation and does not require any prediction on the expected output size. Anyway, for the meantime your proposed API is commited.

    点赞 评论 复制链接分享
  • weixin_39713814 weixin_39713814 5月前

    Thank you! This request helped us reduce the number of memory allocation, and increased the speed of template rendering.

    点赞 评论 复制链接分享
  • weixin_39834084 weixin_39834084 5月前

    Maksim, you might want use Template.ExecuteWriterUnbuffered() now. I changed a lot inside to make it more performant.

    点赞 评论 复制链接分享
  • weixin_39713814 weixin_39713814 5月前

    Great job! I will check everything, hope now I will have more performance with lest memory allocations. Thank you

    点赞 评论 复制链接分享
  • weixin_39834084 weixin_39834084 5月前

    You can use ExecuteWriterUnbuffered() in combination with the http.ResponseWriter; no buffers needed. Let pongo2 directly write to the connection via ResponseWriter. Should give you maximum performance without having a buffer in between.

    点赞 评论 复制链接分享