Which would boost riding performance more: losing weight, or keeping the weight but a lighter bike? I know that a good bike is not just about weight, so assume that the new bike purely weighs less and not has better mechanical parts.
If you want to get faster, train better.
On flat terrain, weight is virtually irrelevant for your speed. It is only relevant when you accelerate or brake, but not while you are riding at speed. So stop worrying about weight, but focus on your power output and/or the efficiency of your bike.
On hilly terrain, weight is indeed important. But so is muscle mass. And building muscle mass will both help you get up the hills faster, and help you in loosing weight. The important part is doing the exercise, the weight loss is just a bonus, imho.
Of course, if you want to get competitive in even slightly hilly terrain, you absolutely need to keep your weight low (doesn't really matter if it's bike mass or fat) so that you only carry as much weight up the hills as absolutely necessary. In this case, low weight is simply necessary to turn your body's power output into the highest climbing speed possible. But even top athletes need their muscle mass. And believe it or not, they do a lot of training...
The exact wording of relevant bits of the question is:
losing weight or getting the same weight less in a lighter bike ... assuming that the new bike purely weighs less and not better mechanical parts.
If we take the question's wording literally, then if you lose a certain amount of weight without affecting your physical fitness, that should be equivalent to losing the same amount of mass from the bicycle if all else is held equal. The issue is that holding all else equal is difficult.
The issue with this is that if you're overweight and you lose weight cycling, your physical fitness most likely goes up. So, not all else is equal.
Additionally, while it's likely this situation doesn't apply to you, it's worth stating that if you are already fairly lean and you lose weight, you can reduce your physical fitness. If you're interested in this side of the problem, Google relative energy deficiency in sport (RED-S). This syndrome can affect both men and women, although women face additional social pressure regarding weight and they may affect their reproductive health long term (more so than men) if they get RED-S. This is receiving increasing amount of attention in professional cycling, and I suspect all sports that have weight classes or involve some sort of power vs weight test face this issue.
On the side of the bicycle, we don't know what your baseline bicycle is. If you are going from a city hybrid to even an entry-level serious drop bar bike, chances are the bike will be lighter and noticeably faster. In that comparison, most gains will probably come from better tires and a lower and more aerodynamic position. For mountain bikes, the gains from a low end to a nice bike might be even greater due to improvements in suspension (although your skill may limit your performance). If your baseline bicycle was a good-quality performance bike, then it's now well documented that improvements in aerodynamics, drivetrain friction, and rolling resistance are far more powerful in most situations than weight losses. Strictly speaking, it's probably more cost-effective to improve your own physical fitness than to improve your bicycle. Also, if you get parts that are much too light, you can sacrifice durability, although that tends to happen at much higher price points.
Last, there are also non-objective considerations. Lighter bikes can feel a lot nicer to ride than heavier ones. They often feel faster and pleasant to ride, even if they are not actually much faster. If that feeling would get you to ride more, it is something worth considering.
When some years ago I decided to start doing multi-weeks cycling vacation, I asked myself how to make sure I could manage riding about 100 km a day, several days in a row.
Since I already had a light bike for touring (aluminum frame and carbon fork, 7-8 kg), what I could save with a lighter bike which was going to be loaded with panniers was way less than what I could save by losing some weight.
So I paid more attention to my eating, and managed to drop about 12 kg over the winter. Since those kg were mostly fat, it didn't negatively affect my performance, it just allowed me to wear cycling gear and slim fit shirts without being afraid of ripping them open :D.
Unless you are riding a fence with wheels, I think there is more margin of maneuver on your weight than on your bike.
As asked, only dealing with weight change, not considering other factors that make a bike rider faster.
For highly trained cyclists, losing weight means losing muscle mass, presumably from muscles that power the bicycle. For these people, losing weight from the bike is the preferred option.
For most riders, losing weight is not only possible, but if done to a plan suitable for someone who care about performance, will also increase muscle mass. For these riders, its probably cheaper and more effective as a performance gain to lose weight.
For most of us, putting down cash on a lighter bike has the dual effect of not only providing a lighter total weight. Not only the lighter bike, the weight loss in the wallet cannot be ignored, as even when the wallet is left at home, there is a psychological effect that is carried on the bike.
However riding is far more complex than power to weight. Weight has a linear effect when accelerating and climbing and descending, but aerodynamics operates to a square law of speed. Above even a moderate speed, drag become more important than weight. A super light rider has lower power to go with the low weight. This is great on hills where power to weight is what counts. On the flat, especially head winds, drag quickly becomes the limiting factor, and a more powerful rider, typically bigger, has a much higher power to drag ratio.
Of course, everyone likes to worry about weight and power, very easy beans to count these days and can be given hard, quantified numbers (My bikes 5.3kg, I am 75.7kg and I produce 423.79W). Drag on the other hand is ignored in most discussions involving cycling beyond "less is better, here is how to get less", as it's practically impossible (i.e. insanely expensive) to quantify and come up with hard numbers. (Every article on any piece of kit gives weight to the microgram, none give a number for drag.)
That depends! Alot of people who use the gym seem to know that muscle weighs more than fat. It's a fact that many good riders who are heavier put out more power than the lighter riders, but the power to weight ratio may work against vs a lighter, less powerful rider. The power rider may win the sprint, the lighter rider may fly up the hills with less effort.
Back in the real world, there are a significant proportion of people for whom buying a bike at 2kg lighter than the old one is "easier" than losing 2kg of body weight, which all helps with acceleration and going uphill.
Hopefully someone will give you a better answer!
When riding uphill it’s simple: Speed is all about power output vs. total weight. It doesn’t matter where the weight comes from. If you can reduce weight without decreasing power output your speed will improve.
In flat-ish terrain or during descents drag is more important than weight. Time trial bikes and wheels are usually noticeably heavier than lightweight road bikes but have much better aerodynamics and are therefore faster on flat terrain. The seating position is also often uncomfortable to the point of reducing power output but the gains in drag reduction are worth it. For the rider it mostly boils down to power output vs. frontal area.