There is a lag between the time when I press the switch and the time when the MIDI message is sent out. How can I fix this?

There are several possibilities to this.

Switch sensitivity

This can be adjusted in the Switch Sensitivity setting in the Main Config menu. The switch sensitivity determines how fast dual switch presses are read. A lower sensitivity will make it easier to engage a dual switch press function. If you change the setting to 5, you'll notice that the delay will decrease. You can make use of the Looper mode function, which decreases the delay to close to 0. However, you'll find that dual switch presses to change backs etc are not possible in this mode.

Double Tap

If you have a Double Tap action programmed into your preset, there will be a delay as the controller is checking if a Double Tap action will occurring, before sending out the message.