Report comment

Thank you for your quick reply. I had some time to try different things and I noticed that in client mode (using your script), my pi gets a very strange IP address, that does not look like the one it normally gets:

wlan0: flags=4163 mtu 1500
inet netmask broadcast
inet6 fe80::4123:a746:4449:c48b prefixlen 64 scopeid 0x20
ether b8:27:eb:55:56:da txqueuelen 1000 (Ethernet)
RX packets 255 bytes 31895 (31.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 393 bytes 47206 (46.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

If I do ssh pi@ instead of ssh pi@raspberrypi.local, it connects instantaneously. However, things like:
sudo apt-get update are still very slow.
Does this ring any bell?

I switched off IP-forwarding but that does not seem to make a difference.