Spread the halved or quartered cherry tomatoes on a sheet pan over parchment paper or aluminum foil, then drizzle with olive oil, sprinkle a little bit of sugar, then add the salt and some chilli pepper flakes.
Toss with your hands to coat them well, then spread them again and put in a preheated oven at 220°C (430°F) on the top rack for about 10-15 minutes or under the broiler for about 5 minutes or until they start to caramelize.
Add the spaghetti to the boiling water and after a few seconds mix with a fork or tongs so they don't stick together.
Add the olive oil in a large pan with the garlic and cook at low heat so the garlic will confit and will not burn. If it browns too quickly, remove the pan from the heat for a little bit so the oil will cool down.
When the tomatoes are caramelized, take them out of the oven.
Remove the pan with oil from the heat, drain the pasta and add it to the pan (be careful, if the oil is too hot the water drops will "explode" at contact and will splatter all over).
Add the chilli pepper flakes and toss the pasta well so it gets nice and oily. Serve with the roasted tomatoes on top, some shredded basil and grated Pecorino cheese.
Notes
I like to serve the garlic as well with the pasta because if cooked properly it will become mild and sweet in flavor. But you can choose to serve it or not, some people don't like garlic that much!