How does PCIe switch handle Gen4 to Gen3?
PCI express links are based on link partners. The maximum rate for a given pair is the slowest of the available link speeds.
If you connect a gen 3 port to a gen 4 port, then the maximum rate for that pair will be gen 3.
With a switch (which is really hubs), each port will train to the maximum rate available provided your layout supports it. If you have gen 3 and gen 4 ports then each will train accordingly.
So you can have a gen 4 switch with ports at different rates.
Note that the overall link performance depends on payload size and the amount of data. Small files sometimes benefit from smaller payload sizes but this is very application dependent and is a design choice.
Profiling the links is often necessary for overall optimal performance.