The stock market finally got a burst of energy on Wednesday, as investors finally saw the possibility that the economy would hold up better than many had feared. Stock market benchmarks were up as much as 1.5% at midday, with particular optimism about what tech-related companies could say in their upcoming earnings reports.

In contrast, retail stocks have weighed on stock market sentiment lately. Yet on Wednesday, even the retail sector participated in the rally, with Abercrombie & Fitch (ANF 5.74%) and Williams-Sonoma (WSM 0.17%) posting sharp gains. Here's everything you need to know about how these two companies managed to do better than their peers and inspire shareholders with visions of a more prosperous future.

A&F mounts a strong recovery

Shares of Abercrombie & Fitch jumped 24% at midday on Wednesday. The apparel retailer reported fiscal second-quarter financial results for the period ended July 29 that pointed to a strong rebound in the company's performance.

A&F reported net sales of $935 million, which rose 16% year over year. Comparable sales across the company gained 13%, and gross profit soared as a result of lower freight costs. Net income soared, with earnings more than tripling from year-ago levels to $1.10 per share.

Looking in more depth, the Asia-Pacific segment rebounded the most, with reopenings in China helping to send comparable sales up 26%. Yet the core Americas segment also had strong sales growth of 19%, and comps were up 14%, which helped to offset slower growth in Europe, the Middle East, and Africa. The namesake Abercrombie brand produced most of the company's growth, as Hollister lagged behind with just single-digit sales gains.

Abercrombie & Fitch boosted its guidance as well, now expecting net sales to climb 10% year over year in fiscal 2023. With new interest in A&F's clothing styles and impressive work in reducing inventory to optimal levels, the retailer appears to be poised to sustain the momentum that has sent the stock to levels not seen in a decade.

Williams-Sonoma feels at home

Elsewhere, shares of Williams-Sonoma were higher by 13% early Wednesday afternoon. The home goods retailer's fiscal second-quarter results for the period ended July 30 didn't look nearly as good as Abercrombie & Fitch's numbers, but they nevertheless exceeded what investors had expected to see and signaled a prospective turnaround down the road.

Williams-Sonoma's financial results didn't look too good on their face. Sales dropped 13% year over year to $1.86 billion, and gross margin took a hit of nearly 3 percentage points. Net income of $202 million was down nearly 25% from year-ago levels. That resulted in earnings of $3.12 per share, which, while down from where they were in the fiscal second quarter of last year, were nevertheless better than many had expected.

CEO Laura Alber put the results in the context of the current macroeconomic picture. As Alber sees it, Williams-Sonoma faced an industry that has seen rising levels of promotional activity, which often end up hurting profit margin figures. In addition, the retailer wasn't immune to softening conditions across the retail industry. Yet the CEO highlighted efforts to maintain pricing power, boost customer service, and keep costs under control, and that helped to keep Williams-Sonoma's financial performance from being any worse.

Williams-Sonoma now expects a deeper downturn in annual revenue of between 5% and 10%. However, higher operating margin could help cushion the blow to the retailer's bottom line, and in the current market environment, profitability is taking a higher priority over sales growth.