Timeline for answer to Initiate all potential props of the object right away or as you go? by jmrk
Current License: CC BY-SA 4.0
Post Revisions
7 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Dec 25, 2024 at 1:18 | comment | added | jmrk |
@KLASANGUI nope, nulling out the prototype saves nothing, because the Object.prototype exists as long as even a single object refers to it. And each object (well, each shape) needs an internal __proto__ slot either way, which can either point at null or at an actual prototype, so again it doesn't get smaller by setting that to null.
|
|
| Dec 25, 2024 at 1:16 | comment | added | jmrk | @Barmar true, but per OP we have "100K+" objects, and for performance you wouldn't want to have that many object shapes flying around if you can avoid it. | |
| Dec 24, 2024 at 8:36 | comment | added | Jurijs Kovzels | @jmrk thanks a lot, marking as correct because it is very insightful even if it's 'it depends' at the end, but that is what I needed. I wanted my assumption checked to know which direction to experiment. | |
| Dec 24, 2024 at 8:31 | vote | accept | Jurijs Kovzels | ||
| Dec 24, 2024 at 2:58 | comment | added | KLASANGUI |
I like to use Object.setPrototypeOf({}, null) instead of Object.create(null) because it produces an instance with no prototype chain (there's not even a constructor property). But the resulting instance will not be Object compatible as it loses all of Object.prototype inheritance and will contain exclusively the properties set into them. Still, a question remains... Discarding the Object.prototype from the prototype chain will help save memory in long lived instances? Or is it irrelevant because it'll be only excluding a reference (very small data) in the instance hashtable?
|
|
| Dec 23, 2024 at 23:50 | comment | added | Barmar | The first paragraph only applies if there are multiple objects like this one. If each instance is unique, it seems moot. | |
| Dec 23, 2024 at 23:26 | history | answered | jmrk | CC BY-SA 4.0 |