JavaScript 'new' vs Object Literals: Performance

preview_player
Показать описание

If it's faster to use object literals or other forms of object creation in JavaScript, why would anyone use the "new" keyword and constructor functions? Does it make a difference when it comes to the application performance vs the readability and expressed intent of the code?

In this episode of ThoughtsOnCode, Derick answers these questions from a viewer, diving into the idea of performance optimization and measurement.
Рекомендации по теме
Комментарии
Автор

Derrick, please get a camera stand :)

AkosLukacs
Автор

You get to my very personal point: JavaScript is not the language I would like to use. I just use it because I am most fluent in it and most people are speaking it. I wish I could use rust anywhere but since I have to run my logic inside state machines like JScript engines written before 2000, I want to fight the con_ains as much as possible. But I do it for fun, for my feelings. Like writing a demo for an old c64.

lp
Автор

Is Michael J Fox filming you? Anyway, I would note that javascript gaming and GIS engines (and canvas use in general) requires these performance considerations you're so actively dismissing. An 8x instantiation penalty is not trivial when you may have 60 frames per second of complex vector data. Take a million point object with each vertex being an object (e.g. example a dynamically generated firework burst in an ad or game, or the coastline of a rapidly zoomed map). Also, the host browser/ js engine may be running on a device made of turd, which is common due to the wide distribution of JS on portable devices. I think understanding WHY there is an 8x difference is the critical mystery and am disappointed you never tackled it.

calworthingtonjr.
Автор

People might not understand this...
It's 35000 objects in 1ms.

damiantoczek