SAN FRANCISCO — Twitter said Tuesday it plans to lay off up to 336 people, slashing about 8 percent of its global workforce in an effort to turn around the social media company that has struggled to attract new users and impress Wall Street.

The cuts come during Jack Dorsey’s second week as permanent CEO and underscore the micro-blogging site’s difficulties in growing, particularly when compared to other social media giants such as Facebook, LinkedIn and Snapchat that are rapidly hiring and expanding their headquarters. Some analysts are wondering whether Twitter, which is rolling back its office expansion in San Francisco, can catch up.

“It is odd to see job cuts this early on, and I think it’s in part a reflection of management execution and strategic errors,” said Mark Mahaney, an analyst at RBC Capital Markets.

Since going public in 2013, Twitter has more than doubled its workforce, growing to about 4,100 employees in more than 35 offices worldwide, according to the company’s website.

Dorsey said in a frank email to employees on Tuesday that the tech firm is focusing on how to attract more people to its site and video apps Vine and Periscope.

“Product and Engineering are going to make the most significant structural changes to reflect our plan ahead. We feel strongly that Engineering will move much faster with a smaller and nimbler team, while remaining the biggest percentage of our workforce. And the rest of the organization will be streamlined in parallel,” Dorsey said in the email.

Other tech firms including software giant Hewlett-Packard, social gaming company Zynga and e-commerce site Groupon have also cut employees this year in attempts to better organize their workforce.

The company declined to say how many of those layoffs will come from its San Francisco headquarters or how much money it will save from restructuring.

Twitter’s stock jumped by about 5 percent after the news, but its gains dwindled throughout the afternoon. It closed at $29.06 per share, up about 1 percent.

“It’s bad news for people who are losing their jobs, but for almost everyone else it’s good news usually. For software companies there’s an extra twist to this. While you certainly need software engineers by the dozens to build large products, sometimes software engineers can get in the way of each other and smaller teams can be more productive than larger teams,” said Roger Kay, president of Massachusetts-based Endpoint Technologies Associates.

While layoffs show investors that Twitter is serious about making changes, Dorsey still has to prove that cutting more than 300 jobs from the company is the right move.

“You don’t grow by shrinking so, in the end, the layoffs have to be in service of a larger growth strategy, and in Twitter’s case, the challenge is to grow users, not simply to grow revenue. At some point, Dorsey will have to demonstrate how it helps him focus on things that are consistent with his vision,” said Nicholas Donatiello, who lectures about management at the Stanford Graduate School of Business.

Dorsey said in the company’s last earnings report that Twitter needs to be easier to use in order to help attract new users.

Some former Twitter employees, including Bart Teeuwisse, used the site to talk about their own layoffs.

Teeuwisse, who has worked as a senior software engineer at Twitter since 2011, found out he was laid off when he was locked out of his work email account. Teeuwisse tweeted that he was working from home and missed a voicemail message from the company informing him he lost his job. Teeuwisse did not immediately respond to a message from this newspaper.

With 316 million users, Twitter isn’t standing idle, bringing back company co-founder Dorsey as chief executive last week and rolling out a new feature called Moments to make it easier to follow live events and trending topics.

“This isn’t easy. But it is right. The world needs a strong Twitter, and this is another step to get there,” Dorsey said in the email to employees.

Laying off employees also helps Twitter to rein in its spending, which draws more scrutiny from investors when the company isn’t making a profit. The company raked in $502 million in sales from April to June, beating Wall Street’s expectations, but also reported a net loss of $137 million.

The restructuring is expected to cost Twitter $5 million to $15 million, according to a filing with the U.S. Securities and Exchange Commission.

Twitter expects its third-quarter earnings, which are scheduled for Oct. 27, to be at or above its forecast, which at the high end is an estimated $560 million in revenue and includes adjusted earnings of $115 million, according to the filing.

“Twitter had a lot of projects in its pipeline, and it looks like now that pipeline will be narrowed to focus on only the products and enhancements that will have the biggest impact on what matters to Twitter,” said Debra Aho Williamson, an analyst with eMarketer. “And what matters to Twitter is increasing its user base and user engagement, and keeping its advertisers in the fold.”

Queenie Wong covers social media businesses, including Facebook, Twitter and LinkedIn, for The Mercury News. She grew up in Southern California and is a graduate of Washington and Lee University where she earned bachelor's degrees in journalism and studio art.

DirecTV Now has some attractive features, including its price, but the overall service is disappointing and an inadequate substitute for a traditional pay TV package, Tech Files columnist Troy Wolverton says.