Ecu mapping is a very specialist area. Essentially and broadly speaking the ecu manages the air/fuel mixture, fuel injection and spark based on input parameters it receives from various sensors monitoring air tempt, air pressure, crankshaft position sensor, camshaft sensors, engine speed, knock sensor, lambda oxygen sensor measuring exhaust gas oxygen content.
To truly tune an engine a rolling road setup is needed and the ecu hooked up to a pc via which various parameters can be altered to improve power, mileage, etc. at various engine speeds and loads.
A Stock ecu can also be "reflashed" ie a new engine management software be downloaded to improve performance or also an additional hardware box be piggybacked onto the stock ecu to do the same job. These two are the easiest options compared to doing rolling road tuning with a programmable ecu. The rolling road tuning with programmable ecu will give far better results but not worth it for an ordinary road car. Also the programmable ecu is coupled with other upgrades such as throttle bodies, turbos, superchargers, reboring, hot camshafts, etc etc etc to name just a few.
I run a DTA fast programmable ecu on one of my cars and it is truly an amazing piece of kit pushing bhp up by almost 40 horses on a moderately modified engine.
An excellent read is Engine management by Dave Walker.