Question: How could a UPS switch between battery and AC wall socket fast from around 4 ms to 12 ms. What make it especial to switch in that very low time. As far as I know it has relays inside it to perform the switching action, but the relay itself can't switch as fast. I am asking this because I need something to switch between 2 DC lines and I tried multiple 12 V DC relays to 30 amps ones and my devices still has to switch off or to reboot once the main DC power source cutt so the backup can't keep up.

I have a DC power system and AC one. The DC works as the backup batteries and the AC is the city power which I don't care about consumed watts from it, but what I care about is every watt from my batteries as 70% of time I am on batteries.

I have a mini DC gaming rig with 60 watts GTX 1060 and low powered I3 8th gen and my total consumption is around 110 watts per hour. The PC is meant to work on battery systems as his input voltage is from 6 to 36 voltage wide input range and can use 250 watts max components.
I already own an AC to DC 12 V adpater 300 watts to power it up, but I don't want it to switch off every time I lose the city power suddenly and I would like to keep it on so I bought a bunch of relays to switch between the AC to DC 12 V adapter and the 12 V battery system but none of them worked properly so I refunded them as the PC has to shutdown or restart at every power switching.

Note that of course I won't use inverter, switch the internal power supply to another AC power supply and use normal UPS to increase my power consumption to double of what I already have..... so please don't suggest AC stuff

Answer: 
Answer you don't switch AT all.
You connect the battery and AC/DC converter at the same time.
The battery is constantly being charged so discharge is not a problem.

If you feel like it you can add a couple diodes to prevent back flow of electricity from the PC to the battery. In fact you could add 2 sets of diodes, but its probably over kill.

The battery power is ON 100% of the time so there should be 0 switching time.

This is a simplified version of how online/inline UPS work that have no switching time.
The reason a UPS switches over "fast enough" is exactly that it switches the AC side: The PSU in your PC is a switching power supply, this means, that it stores a significant amount of energy in itself.

Desktop power supplies are typically designed to store enough energy, that loss of a single half-wave on the input side will not cause interruption of the DC output. Server power supplies are usually designed with double that, so that loss of full wave on the input side doesn't cause an interruption on the DC output - this is because server PSUs are usually used as redundant pairs and the survival interval of half a wave must be achievable as well if the server runs on only one PSU.

UPSes are designed to need less than a half-wave for switchover (less than 10ms on 50Hz), so the amount of energy stored in the PSU comfortably bridges the gap caused by the UPS switchover.

On the DC side, there is no such survival interval - even a bloss of DC for a few NS will cause a malfunction, so not even the fastest relais will be able to switch. In addition to that, the PSU supplies a digital "Power Good" signal to the Motherboard, which will go inactive even if an alternative DC source is available.

To overcome this, you need (at least) to:

* Add survival capacity to the DC side (normally by capacitators)
* Rewire your "Power Good" signal to keep active if the alternative power is available (if your motherboard doesn't ignore it as many consumer boards do)

This is very intrusive, so you might consider using a double-conversion system, either a prebuilt UPS or a DIY version: The losses from double conversion have been greatly reduced with newer microcontroller-based inverters. This gives you the option of not being picky about your PC, Display etc. components.