简体   繁体   中英

How much does Javascript garbage collection affect performance?

I'm writing a bunch of scripts that present images serially (eg 1 per second) and require the user to make either a keyboard or mouse response.

I'm using closures to handle the timing of image presentation and user input. This causes garbage collection to happen pretty frequently and I'm wondering if that will affect the performance (viz. timing of image presentation).

Depends on how the closures work and the images. For instance a system which has about 5 different images but 20 different kinds of input would run more efficient if the closures know about the image but take the user input as argument, rather than vice versa -- because you can make do with a maximum of 5 of those closures at any given time as opposed to about 20.

Also you might be able to convert this into a system that works like:

  1. Image display object a single instance of which can be re-used over multiple images (it should contain only the most limited amount of state).
  2. User input functions/objects which trigger events.
  3. Event handler for user input which reconfigures (1) depending on the things emited by (2).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM