@@ -63,78 +63,6 @@ const {
63
63
emitDestroy
64
64
} = require ( 'internal/async_hooks' ) ;
65
65
66
- // HOW and WHY the timers implementation works the way it does.
67
- //
68
- // Timers are crucial to Node.js. Internally, any TCP I/O connection creates a
69
- // timer so that we can time out of connections. Additionally, many user
70
- // libraries and applications also use timers. As such there may be a
71
- // significantly large amount of timeouts scheduled at any given time.
72
- // Therefore, it is very important that the timers implementation is performant
73
- // and efficient.
74
- //
75
- // Note: It is suggested you first read through the lib/internal/linkedlist.js
76
- // linked list implementation, since timers depend on it extensively. It can be
77
- // somewhat counter-intuitive at first, as it is not actually a class. Instead,
78
- // it is a set of helpers that operate on an existing object.
79
- //
80
- // In order to be as performant as possible, the architecture and data
81
- // structures are designed so that they are optimized to handle the following
82
- // use cases as efficiently as possible:
83
-
84
- // - Adding a new timer. (insert)
85
- // - Removing an existing timer. (remove)
86
- // - Handling a timer timing out. (timeout)
87
- //
88
- // Whenever possible, the implementation tries to make the complexity of these
89
- // operations as close to constant-time as possible.
90
- // (So that performance is not impacted by the number of scheduled timers.)
91
- //
92
- // Object maps are kept which contain linked lists keyed by their duration in
93
- // milliseconds.
94
- //
95
- /* eslint-disable node-core/non-ascii-character */
96
- //
97
- // βββββ > Object Map
98
- // β
99
- // β ββ
100
- // β lists: { '40': { }, '320': { etc } } (keys of millisecond duration)
101
- // βββ ββββββ
102
- // β
103
- // βββ β
104
- // β TimersList { _idleNext: { }, _idlePrev: (self) }
105
- // β ββββββββββββββββββ
106
- // β βββ β ^
107
- // β β { _idleNext: { }, _idlePrev: { }, _onTimeout: (callback) }
108
- // β β βββββββββββββ
109
- // β β β ^
110
- // β β { _idleNext: { etc }, _idlePrev: { }, _onTimeout: (callback) }
111
- // β ββ β ββ
112
- // β β
113
- // β βββββ > Actual JavaScript timeouts
114
- // β
115
- // βββββ > Linked List
116
- //
117
- /* eslint-enable node-core/non-ascii-character */
118
- //
119
- // With this, virtually constant-time insertion (append), removal, and timeout
120
- // is possible in the JavaScript layer. Any one list of timers is able to be
121
- // sorted by just appending to it because all timers within share the same
122
- // duration. Therefore, any timer added later will always have been scheduled to
123
- // timeout later, thus only needing to be appended.
124
- // Removal from an object-property linked list is also virtually constant-time
125
- // as can be seen in the lib/internal/linkedlist.js implementation.
126
- // Timeouts only need to process any timers currently due to expire, which will
127
- // always be at the beginning of the list for reasons stated above. Any timers
128
- // after the first one encountered that does not yet need to timeout will also
129
- // always be due to timeout at a later time.
130
- //
131
- // Less-than constant time operations are thus contained in two places:
132
- // The PriorityQueue β an efficient binary heap implementation that does all
133
- // operations in worst-case O(log n) time β which manages the order of expiring
134
- // Timeout lists and the object map lookup of a specific list by the duration of
135
- // timers within (or creation of a new list). However, these operations combined
136
- // have shown to be trivial in comparison to other timers architectures.
137
-
138
66
// Remove a timer. Cancels the timeout and resets the relevant timer properties.
139
67
function unenroll ( item ) {
140
68
// Fewer checks may be possible, but these cover everything.
0 commit comments