[SPARK-3896] checkSpeculatableTasks fask quit loop; checkSpeculatableTasks is expensive

1. invoking checkSpeculatableTasks is expensive, once true then return true
2. import section formatting