The legendary investor Peter Lynch once said that "everyone is a long-term investor until the market goes down." That's certainly the case in this market, which is testing the mettle of long-term investors with inflation, rising interest rates, and other macroeconomic and geopolitical shocks.

It's tempting to retreat to the safety of cash, bonds, and cheaper defensive stocks in this challenging market. However, abandoning all of your riskier assets can cause you to miss out on some massive gains down the road.

Instead of blindly panicking, investors should stick with well-run companies that are firmly profitable, generate stable growth, and trade at reasonable valuations. These three tech companies check all three boxes -- and investors can consider buying and holding their shares forever.

An investor checks a stock portfolio on a computer.

Image source: Getty Images.

1. Alphabet

Alphabet (GOOG 0.37%) (GOOGL 0.35%), the parent company of Google, should remain a top tech stock for decades because its ecosystem is nearly inescapable. It owns the world's largest online search engine, the most popular mobile operating system (Android), the top web browser (Chrome), the leading webmail service (Gmail), and the largest free streaming video site (YouTube).

The tech giant also owns the world's third-largest cloud infrastructure platform, a driverless vehicle division, and an experimental life science divisions. These smaller businesses could gradually reduce Alphabet's dependence on Google's advertising services over the long term.

Between 2016 and 2021, Alphabet's revenue grew at a compound annual growth rate (CAGR) of 23%. Its net income rose at CAGR of 31%. Its stock price has more than tripled over the past five years, and it will likely attract even more attention from smaller investors following its 20-for-1 split in July.

But for now, Alphabet still looks cheap at 24 times forward earnings, which makes it the second-cheapest FAANG stock after Facebook's parent company Meta (META 1.54%). But unlike Meta, Alphabet doesn't face significant privacy-related headwinds and isn't executing a costly transition toward virtual reality hardware and software. Those strengths make Alphabet one of my favorite stocks to buy and hold forever.

2. Adobe

Adobe (ADBE -0.27%) is another one of my favorite long-term holdings because its ecosystem is sticky and its growth is remarkably consistent.

Over the past decade, it transformed all of its flagship Creative software applications -- including Photoshop, Illustrator, and Premiere Pro -- into cloud-based subscription services. That transition locked in its customers and eliminated Adobe's dependence on periodic desktop-based upgrades.

Adobe also expanded its portfolio of enterprise-facing cloud services for sales, marketing, analytics, and e-commerce teams.

That cloud-based transformation enabled Adobe to grow just as consistently as Alphabet. Between 2016 and 2021, Adobe's revenue and adjusted net income increased at a CAGR of 22% and 32%, respectively, as its annual gross margin expanded from 86% to 88%. Its stock price more than quadrupled over the past five years.

I believe Adobe will maintain that momentum over the long term for two simple reasons. First, its Creative Cloud is essential for media and design professionals, and it doesn't face any meaningful competitors. Second, its enterprise-facing Digital Experience services will profit from the ongoing digitization of business processes across multiple industries.

Adobe's stock might not seem cheap at 36 times forward earnings. However, the resilience of its evergreen businesses justifies that premium and makes it a good defensive stock to own as rising interest rates rattle the market.

3. Texas Instruments

Texas Instruments (TXN -1.23%) might seem like a dusty old producer of analog and embedded chips, but its slow and steady growth has generated impressive long-term gains for patient investors.

Between 2004 and 2021, TI grew its annual revenue at a CAGR of just 2%. However, its net income increased at a CAGR of 9%, its earnings per share improved at CAGR of 13%, and its free cash flow per share increased at an average rate of 12% annually.

TI's bottom-line growth outpaced its top-line growth because it stopped competing against higher-end chipmakers like Qualcomm and Nvidia. Instead, it focused on manufacturing cheaper, less capital-intensive analog and embedded chips to reduce its operating expenses and generate consistent cash flows. In recent years, it's been pivoting from 200mm to 300mm wafers to reduce the costs of its unpackaged parts by about 40%.

That transition, which relied heavily on the secular expansion of the automotive and industrial markets, boosted TI's gross margin from 45% in 2004 to 67% in 2021. It also reduced its share count by 46% during that period, while increasing its dividend annually for 18 consecutive years.

TI's stable growth and shareholder-friendly measures helped TI generate a solid total return of nearly 150% over the past five years. The stock still looks cheap at 18 times forward earnings today, it pays a healthy forward dividend yield of 2.8%, and it remains a solid defensive play for long-term investors.