Well, while it may not be an issue, I have heavy concerns about your complete lack of semicolons in your script. Without them, javascript will guess at where the end of your statement is, and it may guess wrong and you may see bugs because of this.
That said, I have no idea what the delete event code does. Maybe you should link to the script you want help with.
Having a very large events array will cause the game to lag, even if it's filled with nulls. That's why I try to reuse event IDs and keep the array as small as possible.
There might be more problems there though, I'll check your sample code tomorrow.
I use a modified version of OrangeCustomEvents on my own game, but to prevent lag I have multiple event arrays (an array for NPCs, one for farm crops, one for animals and one for regular map events). If you're gonna have thousands of events, you should probably have something similar because the regular event array is iterated on many times per frame.
Yeah, I did already think of trying to minimize the growth of the map's event array. I make it eventually start reusing event IDs (when reasonable). Unfortunately, it seems to run into the same eventual performance issues as when the array growth is left unchecked, though. So it should be related to those events (or something related to them, like self switches being created for them or something?) merely existing.
In both cases, the performance issues begin to occur after around roughly 3500 duplications and "deletions". I'll also attach a link to the stripped-down, fresh project. ~5mb.
Check if that remove event is removing that events sprite as well. Having too many sprites can lower performance even if they don't have an image.