TRIM is not an operation, it's a command to inform the drive about LBA blocks the OS no longer needs. IOW it sort of 'tells' the drive about a file it just deleted that was stored in LBA 12048 - LBA 14077 for example.
Various protocols have different names and commands (ATA, NVMe, SD Card) but they essentially all do the same thing: tell a drive about sectors no longer needed by OS.
In general when a drive receives a TRIM command it 'unmaps' those LBA addresses that were discarded by the OS which can be done almost instantly as it only needs to edit translation tables. For the SSD it is beneficial to know about these so it can consolidate them and erase them (at IDLE time and as part of garbage collection).
If one tries to read the unmapped sectors, in most cases the SSD controller simply returns zeros without even reading the sectors, which explain why recovery of deleted files on SSD drives is close to impossible (although specific circumstances could prevent TRIM from executing or being processed by the drive).
Windows refers to optimization now, no longer to defragging. Although fragmentation still occurs at the file system level, it has no effect on performance of SSD drives, it can affect file recoverability though.
Although Windows Drive Optimization still performs limited defrag I believe, it also TRIM's not in use cluster space. This in addition to Windows sending TRIM commands immediately after file deletion (if TRIM at OS level is enabled).
fstrim
takes less than 5 seconds for a Btrfs filesystem occupying almost entire SSD of 500 GB.