-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Open
Labels
Description
Currently Deno maintains two sets of globals - one set is “Web native”, available to user code, the other is “Node native” and available to npm dependencies.
This leads to several problems:
- the setup is very complex and requires non-trivial solution at the V8 level
- the performance is absolutely horrible - on each access of a global a stack trace gets collected (most often only a single frame) to determine which global should be used - this causes huge overhead, eg. using
performance.now()
in a tight loop causes lookup of the global to take more time then actually benchmarked code - it’s a mental overhead to figure out which global is gonna get used depending on the code location
Currently the list is as follows:
-
Buffer
(npm, feat: make 'Buffer' and 'global' available as globals #29416) -
clearImmediate
(npm, feat: makesetImmediate
andclearImmediate
as globals #29877) -
clearInterval
(both, but different implementation) -
clearTimeout
(both, but different implementation) -
global
(npm, feat: make 'Buffer' and 'global' available as globals #29416) -
performance
(both user and npm, but different implementation, feat: use a single 'performance' global #29323) -
process
(the availability in Deno depends on project creation time in Deno Deploy) -
setImmediate
(npm, feat: makesetImmediate
andclearImmediate
as globals #29877) -
setInterval
(both, but different implementation) -
setTimeout
(both, but different implementation) -
self
(Deno, fix in fix: removeself
from global middleware #29734) -
WorkerGlobalScope
(Deno, fix in fix: remove WorkerGlobalScope from global middleware #29543)
There are some easy solution here:
- make
Buffer
,clearImmediate
,global
,setImmediate
always available to all code - merge
performance
global to only use “Node” version (which has additional properties compared to the Web one) - make
clearInterval
andclearTimeout
work with both Web (number) and Node (object) timeouts
And there are hard problems related to setTimeout
and setInterval
APIs that changing them will lead to a huge breaking change, while leaving them as is will maintain the complexity.
- Priority: 4
- Technical complexity: 5
Hajime-san and anonhostpi