     private let selector: NIO.Selector<NIORegistration>
     private let thread: Thread
     private var scheduledTasks = PriorityQueue<ScheduledTask>(ascending: true)
+    private var tasksCopy = ContiguousArray<() -> Void>()
+
     private let tasksLock = Lock()
     private var lifecycleState: EventLoopLifecycleState = .open
 

    public func run() throws {
        precondition(self.inEventLoop, "tried to run the EventLoop on the wrong thread.")
        defer {
            var tasksCopy = ContiguousArray<ScheduledTask>()

            tasksLock.lock()
            while let sched = scheduledTasks.pop() {
                tasksCopy.append(sched)
            }
            tasksLock.unlock()

            // Fail all the scheduled tasks.
            for task in tasksCopy {
                task.fail(error: EventLoopError.shutdown)
            }
        }

        self._addresses = UnsafeMutablePointer.allocate(capacity: Socket.writevLimitIOVectors)
        self.msgs = UnsafeMutableBufferPointer(start: _msgs, count: Socket.writevLimitIOVectors)
        self.addresses = UnsafeMutableBufferPointer(start: _addresses, count: Socket.writevLimitIOVectors)
        // We will process 4096 tasks per while loop.
        self.tasksCopy.reserveCapacity(4096)
    }

    deinit {
