Yes,the performance of "run command" way is not so good,if you get timeout errors using SDK, maybe calling rest APIs directly will be a workaround.
In terms of underlying , while you use SDK to call run command function , it calls this API :
POST https://management.azure.com/subscriptions/<your subscription ID>/resourceGroups/<resource group name>/providers/Microsoft.Compute/virtualMachines/<VM Name>/runCommand?api-version=2018-04-01
Request Headers:
Content-Type: application/json
Authorization: Bearer <access token>
Request Body:
{"commandId":"RunPowerShellScript","script":["<script content>"]}
Once you called it successfully , you will get a 202 response code and in response header , there will be a param "location" whose value is a link and you can get your command running status using it :

With this way , you can monitor running status by calling this url instead of waiting for the response for a long time .
Besides "run command" way to run ps script on Azure VMs, there are 3 other ways to do it:
- Azure VM custom script extension
- Remote PowerShell
- Azure Automation DSC
This blog described them well, you can choose one of them based on your requirement.
Hope it helps.