This is an RF system design question.
The short and cryptic answer is the link budget tells you how much performance you need. The real answer is the continual subject of many masters and doctoral theses.
Like most engineering problems it’s a bag of jello - squeeze it one place and it squirts out somewhere else. Not really optimization but rather trade-offs. Better antenna performance gives you better range, or requires less transmit power so you get better battery life, or … Better antenna performance also leads to directions of poorer performance. Search on “Antenna Patterns” for more reading.
So, get advice, test to verify, and make sure you have lots of margin for the stuff you haven’t considered.
The TL:DR is that RF connections are described by a “link budget.” The link budget is transmit power plus all losses and gains, and the receiver sensitivity. If the total number is positive, things work. If it’s negative, they don’t. [Note to the pedants: I’m including any processing gain effects, so shut up about negative S/N.]
Simple, small antennas tend to be poor performers and show up as losses in the budget. Antennas with gain have patterns - some directions have gain, and others have (even higher) losses. If you can be sure your receiver and transmitter are in the area where the antenna has gain, you have the option of the higher gain antenna.
The distance between the receiver and transmitter is a loss factor all it’s own. It’s a square law relationship - double the distance and the loss increases by a factor of four (~6 dB) Search on “Free Space Path Loss” Wikipedia has a decent intro article. Note that few cases are actually “free space” so the path losses have a lot of other loss terms that I won’t bore you (even more) with other issues like fading, mutlipath, and a bazillion other considerations.
An ideal point source antenna that radiates in all directions is called an isotropic radiator. Antenna gains are often specified in dBi (dB relative to an isotropic radiator.) Antenna gains are also frequently described in dBd (dB referenced to a dipole.) A dipole is a simple, fairly fundamental and common antenna type with a gain in it’s main lobe of ~2.15 dBi. The gain off the end of a dipole is a null, so infinite loss. A tradeoff.
Antennas develop gain by squeezing signal energy in some direction. An isotropic radiator’s gain plot is a sphere - equally good (and poor) in all directions. A dipole’s antenna pattern is a torus. Better in a direction normal to the axis of the antenna, and (theoretically) zero off the ends along the axis. [Note to pedants, shut up about infinite Q and the infinitesimal dipole.]
You need to look at the specified gain of the antenna and your link budget. If you have gain to burn, a simpler antenna is generally better. If your budget is negative, you need a better receiver, more transmit power, a better antenna, or another trick up your sleeve.
All these things have limits. We’ll talk abut receiver noise limitations another day.
Rich