Walmart (WMT 0.83%) has been investing heavily to maintain its pole position in the grocery industry. Those investments took a step up over the past year after Amazon (AMZN -0.17%) acquired Whole Foods Market and entered the grocery industry in earnest.

Walmart's investments have certainly paid off. It said it saw its best comparable grocery sales in nine years in the second quarter. But the investments are also cutting into profitability.

Kroger (KR -0.60%), likewise, has been investing in services like curbside pickup and home delivery. Unlike Walmart and Amazon, however, it charges a fee for online orders, even if customers come pick them up at a store. Even though there's a cost involved with preparing online orders for pickup, Walmart and Amazon will do it for free on orders of more than $30 and $35, respectively.

Kroger isn't willing to sacrifice its profits in order to grow, and as a result, it's losing share to Walmart, Amazon, and other competitors. That's a much worse alternative than Walmart's current reality.

A bag of fresh vegetables spilling out on a table.

Image source: Getty Images.

A look at Kroger's results

Kroger's disappointing second-quarter results are best summed up by the 1.6% comparable-store sales growth it posted. While that number's better than the 1.4% it reported in the first quarter, it's a far cry from Walmart's 4.5% increase in the most recent quarter.

Kroger is notably showing progress in its online sales, up 50% year over year in the second quarter. That's a deceleration from 66% in the first quarter, but it's ahead of Walmart's 40% online sales growth (which includes both grocery and general goods).

But Kroger is growing sales off of a minuscule base. Just as Walmart can show a greater online sales growth rate than Amazon but continually lose online market share, Kroger is seeing a similar effect with its business.

At the same time, Kroger saw its operating profit margin fall 50 basis points year over year to 2%. That decline was mostly driven by investments in pricing, a move that follows Walmart's lead.

What would free pickup cost?

Kroger's operating profit decline could have been much worse if it offered free pickup for online orders like Walmart or Amazon. It currently charges $4.95 to $7.99 for online orders in order to cover the labor and expenses associated with picking items from store shelves, packaging them, and holding them for pickup.

Removing the fees would likely increase the number of online orders as well as the costs associated with handling those orders. On the other hand, it could increase total orders by winning over customers who are using Walmart's online option. Walmart has at least one store within 10 miles of 90% of the population, so there's doubtless overlap between its stores and Kroger's.

If Kroger offered free pickup, it would see a $0.10 drop in earnings per share, according to analysts at UBS. However, that analysis only looks at one side of the equation -- how much revenue Kroger would lose by eliminating its fees. It doesn't look at the other side of the equation, which is how much of a sales increase Kroger could see if it didn't charge a fee. Further, there could be room to improve operational efficiency by scaling the service.

Walmart's results show compressing profit margins, but it's also showing a modest increase in overall operating income with its U.S. operations. (International operations dragged on profits as Walmart invests and makes some significant changes in certain markets like India and Brazil.) Kroger's operating profits fell 20% year over year. Most importantly, Walmart is taking share of the grocery industry and effectively defending against Amazon, which is taking share from smaller grocers. Overall, that's a much better situation than Kroger currently finds itself in.