How does the “creation stage" know how much memory space needs to be configured?

In JavaScript: Understanding the strange parts, the instructor explains that the memory for variables is tuned during the so-called creation phase (and that undefined); then a run phase occurs. But why is this useful when we do not know which value (s) the value will later point to?

It is clear that variables can point to many different things - for example, a short string up to the deeply nested structure of an object - and I assume that they can vary greatly in the amount of memory they need.

If phased execution, including variable assignment, appears only at a later stage of execution, how can the initial phase of creation know how to tune memory? Or, is memory reserved only for the name in each pair of variable name / value, with memory for managing the value differently?

+6
source share
2 answers

The instructor refers to the Google Chrome V8 engine (as evidenced by its use in the video).

To simplify memory management, the V8 uses several optimization approaches. First, it will compile JavaScript code, and at compile time it will determine how many variables (hidden classes, later) need to be created. They will determine the amount of initially allocated memory.

V8 JavaScript . , . , V8. 1

JavaScript-, , "" . " "

() (). , , . , , " ". 2

, , .

: . . , , . 2

, , .

, V8 , " ", ( ), .

, JavaScript, V8 3

: , V8 , 3

, , . , , - ( , ).


< > 1. , https://github.com/v8/v8/wiki/Design%20Elements#dynamic-machine-code-generation
< > 2. V8, https://medium.com/@tverwaes/setting-up-prototypes-in-v8-ec9c9491dfe2
< > 3. Fast Property Access, https://github.com/v8/v8/wiki/Design%20Elements#fast-property-access

+5

- , . . Procesor , , , . , - ; , , .. .

0

Source: https://habr.com/ru/post/1017115/


All Articles