Tesla is laying off about 9% of its staff.

"Tesla has grown and evolved rapidly over the past several years, which has resulted in some duplication of roles and some job functions," Tesla CEO Elon Musk wrote in an email to employees on Tuesday. "While they made sense in the past [they] are difficult to justify today."

"We are making this hard decision now so that we never have to do this again," he said.

Only salaried employees will be affected, he added. Musk said the layoffs won't affect production of the Model 3, since no production associates are being be cut. Tesla (TSLA) is still hiring for key positions and will increase its production staff.

Related: Elon Musk has the last laugh as Tesla stock pops 40% from its low

The electric car company needs the Model 3, its more affordable option, to succeed.

Production of the Model 3 stalled in the fall, prompting shareholders to sue the company. But since then, it looks like Tesla got the Model 3 production back on track. Last week, Musk said it's "quite likely" that Tesla will reach its goal of building 5,000 Model 3 cars per week by the end of the month.

Investors are pleased by the turnaround. As of Tuesday, Tesla's stock is up more than 40% from the 52-week low it hit back in April.

The stock lost did lose some gains following news of the layoffs.

Related: Tesla stock up 10% after Elon Musk promises Model 3 production has turned a corner

Musk explained that the job cuts are part of a restructuring, adding that the layoffs should help reduce costs and finally make the company profitable.

He noted that Tesla has never made an annual profit -- a point that's often made by critics. "We will never achieve [our] mission unless we eventually demonstrate that we can be sustainably profitable," he wrote in the letter.

As part of its reorganization, Tesla is ending its solar panel sales agreement with Home Depot (HD). Most Tesla employees working out of Home Depot will have the opportunity to move to Tesla stores, Musk said. Home Depot started selling Tesla's solar energy services in February.

"It is very difficult to say goodbye," Musk said in the letter. He added that affected employees will receive "significant salary and stock vesting," proportionate to the time they spent at the company.

-— CNN's Chris Isidore, Paul R. La Monica and Jackie Wattles contributed to this report.