Messaging-software provider Twilio (TWLO 1.83%) has been one of my least favorite software stocks for a long time. The main reason was the company's bloated cost structure.

To support its core text-message product, Twilio must pay fees to network service providers. These fees push down the company's gross margin far below that of a typical software company. Instead of restraining its spending on sales, marketing, research and development, and other areas to reflect this reality, Twilio has historically spent prolifically as it chased profitless growth.

Push has come to shove

In 2022, Twilio produced $3.83 billion in revenue. Gross profit was $1.81 billion, good for a gross margin of just 47%.

This gross profit wasn't nearly enough to satisfy Twilio's rampant spending. Total operating expenses hit $3.02 billion, with sales and marketing alone eating up more than two-thirds of the company's gross profit. Once all the numbers are tallied, Twilio reported a net loss of $1.26 billion for the year.

A big chunk of those operating costs was in the form of stock-based compensation, but Twilio wasn't profitable, even on a free-cash-flow basis. The company reported a free-cash-flow loss of $334.6 million in 2022.

This situation isn't sustainable and has been made more precarious by the slowdown in demand affecting nearly every enterprise cloud and software company. While Twilio grew revenue by 22% in 2022, it expects just 4% to 5% growth in the second quarter of 2023.

With reckless spending no longer driving growth, Twilio appears to have come back to reality. The company has announced multiple rounds of layoffs, withdrew some employee perks, and is shifting toward remote work to save on office costs. After years of burying its head in the sand, Twilio is finally getting serious about costs.

A good goal

Many unprofitable tech companies that have been forced to reckon with out-of-control costs and massive losses have latched onto bad metrics to measure the progress of their turnarounds. Online used-car retailer Carvana and online furniture retailer Wayfair, for example, both peddle adjusted earnings before interest, taxes, depreciation, and amortization (EBITDA) as their preferred measure of profitability. Both companies are aiming to turn that highly flawed metric positive.

I gained some respect for Twilio's management when it rolled out its long-term plan to become a sustainable, profitable company. Twilio is taking on its excessive stock-based compensation expense, aiming to lower it as a percentage of revenue this year and to reach just 10% to 12% of revenue by fiscal 2027. In 2022, stock-based compensation accounted for a whopping 21% of total revenue.

The company is viewing stock-based compensation as a real expense, which is a breath of fresh air in the world of unprofitable tech stocks. Unlike some of its peers that are putting the focus on heavily adjusted profitability metrics that don't come close to reflecting true profitability, Twilio is aiming to become profitable on a generally accepted accounting principles, or GAAP, basis by fiscal 2027. If it accomplishes that, free cash flow will almost certainly turn positive, as well.

The next few years will likely be tough for Twilio. Growth will probably be slower than it has been in the past, and the company has plenty of additional cost-cutting to do as it pushes toward GAAP profitability. Even after suffering an 89% decline from its peak, the stock doesn't look like a clear-cut bargain. Twilio is still valued at around $8.75 billion, or more than twice annual sales.

The company will try to reignite growth over the next few years, targeting 15% to 25% annual organic revenue growth by 2025. If it can do that and reach profitability, the stock could be a long-term winner. There are no guarantees, but Twilio's clear-headed focus on producing real profits gives me more confidence in the company than I've ever had in the past.