Object pools in high performance javascript?

前端 未结 5 1248
别跟我提以往
别跟我提以往 2021-01-29 21:53

I\'m writing some javascript code which needs to run fast, and uses a lot of short-lived objects. Am I better off using an object pool, or just creating objects as I need them?<

5条回答
  •  旧巷少年郎
    2021-01-29 22:00

    I think that it depends on the complexity of your objects. I recently optimized a JavaScript word processor that used JS objects paired with DOM Objects for every element in the document. Before implementing an object pool the load time for my test document was about 480ms. The pooling technique reduced that to 220ms.

    This of course is anecdotal, but in my case it increased the snappiness of the app considerably and I now use pools often in applications with high object turnover.

提交回复
热议问题