Which endstops are most precise?
There are some different criteria that we should use to select a switch type:


Precision / repeatability: does the switch trigger at the same place every time? How much spread is there in the trigger position? Do environmental changes or machine setting changes affect the trigger position?
Contact distance: does the switch register with enough clearance to its hard-stop that the homing axis can stop before colliding with something?
Noise-rejection: does the switch ONLY trigger when it is supposed to? 


It's important to ask, how much switch precision do we actually need? A typical 3d printer drivetrain using a microstepping stepper motor can only accurately position the moving load within +/- one 1/16th microstep (even if using finer microstepping than that) due to error-inducing effects like friction torque and magnetic detent angle error. That's around +/-0.01mm for most printers. The homing switch only needs to be as precise as the motor's positioning! Nothing is gained by having, say, 0.001mm precision endstops. 

This precision of +/-0.01mm is achievable for all types of endstop switches, with proper switch selection and configuration. 

Then there are three "standard" switching types in use in consumer/hobbyist 3d printers:


Mechanical switches, typically dual NO/NC limit switches, which either pull up or pull down a signal pin by connecting an electrical circuit when triggered
Optical switches, which use transistors to detect when an obstacle ("flag") is blocking the window between the emitter and sensor
Hall effect switches, which use transistors to detect when a magnetic field exceeds a particular field strength cutoff


Mechanical Switches

Precision/repeatability depends on the switch quality, length of lever arm attached (longer increases contact distance but is worse for precision), and impact speed of the carriage with the switch. It's possible to have a good mechanical switch or a bad mechanical switch. This is typically a reasonable default choice because it is simple and cheap. 

A small mechanical switch with a short lever arm (or the lever arm removed) will generally achieve the required +/-0.01mm switching precision. Very cheap switches, high contact speeds, and long lever arms may provide inadequate resolution for Z homing or probing, but will still be adequate for low-precision X and Y homing purposes. 

Where mechanical switches tend to cause issues is in noise rejection. Different controller boards use different ways of wiring the switch: some use two wires and only send a signal when triggered. When not triggered, the signal wire is left floating or weakly pulled up by the microcontroller, while attached to a long wire that acts as an antenna to pick up EM noise. It is VERY common for heater or stepper wiring to emit nasty EMR due to the PWM current control. Two-wire endstop cables should always be run away from stepper and heater wiring. Shielding and twisting the conductors is a good idea too. 

A more robust approach is to use three-wire switches that actively pull the signal line high or low depending on the switch position. These will tend to reject noise better. 

Very cheap mechanical switches may fail within the life of the printer. However, most limit switches are rated for millions of cycles, which is unlikely to occur over any normal printer's lifespan. 

Mechanical switches are easy to align and easy to trigger by hand during troubleshooting. 

Optical Switches

These rely on a flag blocking a window between a light emitter and a detector. This is non-contact and can be quite reliable, but introduces some challenges. The exact trigger position (and thus precision) may depend on ambient light levels in the room, because the sensor is monitoring for light to decrease below a specific intensity. So it may be very repeatable/precise in the short term but have some drift if the sensor moves in and out of the sun through the day.

Switching tends to be more consistent and reliable if the flag enters the window from the side, rather than the top. 

Optical switches will actively pull the signal line high or low, and thus have good electrical noise rejection.

Hall Effect Switches

These measure the intensity of the nearby magnetic field and trigger when it exceeds a certain amount in a certain polarity. This is highly precise/repeatable (better than +/-0.01mm) and extremely resistant to noise and environmental conditions. (Unless your printer is next to something that emits large magnetic fields, anyway.) 

The hall switches I've seen have an adjustable trim pot to tune the trigger distance. That's a nice feature when trying to manually calibrate a Delta or a Z-bed for first layer height. 

The primary downside to hall switches is that they need a magnet to trigger the switch. This can be difficult to trigger by hand during troubleshooting, and requires attaching a magnet somewhere on the moving carriage. Glue works fine... but don't glue the magnet in place backwards!