That said, the immediate impact on earnings and the company’s stock price have been less rosy.

The question for Walmart is ultimately whether that short-run hit makes the company a stronger competitor in the long run. Will the investments turn out to be the beginning of a change in how Walmart and other giant companies think about their workers, or just a one-off experiment to be reversed when the next recession rolls around?

The future health of the United States economy, and the well-being of its workers, may well depend on the answer.

Pressure From Investors

On the morning of Feb. 19, 2015, Walmart’s 1.2 million employees across the United States gathered — many in front of their stores’ vast walls of televisions for sale — to watch a video feed by their chief executive. Doug McMillon, wearing a sweater and sitting in the office once occupied by the company founder Sam Walton, more or less acknowledged that Walmart had made a mistake. It had gone too far in trying to cut payroll costs to the bone.

“Sometimes we don’t get it all right,” Mr. McMillon said in the video. “Sometimes we make policy changes or other decisions and they don’t result in what we thought they were going to. And when we don’t get it right, we adjust.”

What most store employees probably didn’t know was that Mr. McMillon and his executive team, who had been promoted into their jobs a year earlier, were under extraordinary pressure from investors. They needed to reverse a slide in business and fight off threats in all directions — dollar discounters on the low end, Amazon online, direct competitors like Target and countless rivals specializing in one slice of Walmart’s business, from grocery chains to home-improvement warehouses.

People were shopping more — at Walmart’s rivals.

The company offers its millions of shoppers a simple way to make their dissatisfaction known. On the back of sales receipts is a message, “Tell us about your visit today,” along with instructions to log on to a website and answer questions about the store: Was it clean? Were they able to get what they came for quickly? Were employees friendly?

In early 2015, the answers that poured into Walmart’s global headquarters were, in a word, awful. The people paid to analyze the company tended to agree, too. A report by analysts at Wolfe Research in 2014 included photographs from a visit to Walmart of a sad-looking display of nearly empty bins of oranges and lemons and disorganized shelves of crackers.