     public func run() throws {
         precondition(self.inEventLoop, "tried to run the EventLoop on the wrong thread.")
         defer {
-            var tasksCopy = ContiguousArray<ScheduledTask>()
-
+            var scheduledTasksCopy = ContiguousArray<ScheduledTask>()
             tasksLock.lock()
+            // reserve the correct capacity so we don't need to realloc later on.
+            scheduledTasksCopy.reserveCapacity(scheduledTasks.count)
             while let sched = scheduledTasks.pop() {
-                tasksCopy.append(sched)
+                scheduledTasksCopy.append(sched)
             }
             tasksLock.unlock()
 
             // Fail all the scheduled tasks.
-            for task in tasksCopy {
+            for task in scheduledTasksCopy {
                 task.fail(error: EventLoopError.shutdown)
             }
         }

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


        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 {
