The S&P 500 is still in negative territory this year, but it did have a strong performance last month, rising by 9%. A couple of stocks that did exceptionally well and beat the markets by a wide margin include 1Life Healthcare (ONEM) and Rivian Automotive (RIVN 4.92%). Both rose more than 30% in value.

What was behind their recent surges, and are they investments you should consider adding to your portfolio today?

1. 1Life Healthcare

Up until July, it wasn't a good year for 1Life Healthcare, which also goes by the name of One Medical. At the end of June, the healthcare stock had lost more than half of its value. The company offers primary care services and hasn't been immune to the softness in the market this year. A lack of profitability has also made it a riskier buy than other growth stocks.

But the drop in value made its valuation more attractive. That appeared to be the case, at least to Amazon, as the tech giant announced last month it planned to acquire One Medical for $3.9 billion, or $18 per share. That led to shares of One Medical hitting highs they haven't been at since the start of the year. The stock doubled from less than $8 at the end of June, and today it trades at around $17 per share.

What's bittersweet for investors is that the $18 purchase price effectively creates a ceiling for how much higher the stock will go. Although there may be some fluctuations and opportunities for arbitrage, there likely won't be a significant change in the price from here on out unless the acquisition falls through -- in which case, the stock could fall drastically.

In the case of One Medical, it's likely too late to buy the stock and earn much of a return at this stage.

2. Rivian Automotive

Electric vehicle maker Rivian had a more modest rise in price last month, climbing 33%. It's still a substantial incline, and that's not due to an acquisition. In early July, the company released its second-quarter production and delivery numbers, which proved to be impressive. It produced 4,401 vehicles for the period ended June 30 -- 72% higher than the 2,553 it produced just a quarter earlier. Deliveries totaling 4,467 were also more than three times what it reported in the first quarter (1,227). It also asserted that it was on track to hit its target of producing 25,000 vehicles this year.

Those improved numbers helped propel the stock early on in the month. And shares got another lift toward the end of July when the company's management said that it was laying off 6% of its employees. The job cuts will help the company shed some much-needed expenses as Rivian's quarterly net losses have often totaled more than $1 billion.

Rivian is still in its early growth stages, but it is backed by tech giant Amazon, which announced plans last month to use the vehicles in over 100 U.S. cities before the end of this year. And by 2030, it expects to be using them in 100,000 cities.

The Amazon partnership does lend Rivian a bit of safety. There is some promising potential here, but this is still not an investment I would consider at this stage given the company's steep losses and high valuation -- Rivian trades at more than 200 times its revenue.