Model X back in 2015. "/>

Tesla CEO Elon Musk, currently traveling in Asia, signed an agreement Tuesday with officials in Shanghai to build a factory with the capacity to produce up to 500,000 vehicles per year. Shanghai officials describe it as the largest foreign-funded manufacturing project in Shanghai history.

The deal comes in the midst of an increasingly bitter trade war between the United States and China. A 25 percent Chinese tariff on US-made cars recently forced Tesla to raise the Chinese price of the Model S and Model X. Having a Chinese factory would help Tesla avoid these taxes, as it could manufacture cars in China and then sell the cars directly to Chinese consumers—or to customers in Asian countries with good trade relationships to China.

Tesla's China project was first reported by Bloomberg. A Tesla spokesperson confirmed the news to Ars Technica.

"Last year, we announced that we were working with the Shanghai Municipal Government to explore the possibility of establishing a factory in the region to serve the Chinese market," Tesla said in a press statement. "Today, we have signed a Cooperative Agreement for Tesla to start building Gigafactory 3, a new electric vehicle manufacturing facility in Shanghai."

After obtaining the necessary permits, Tesla says, "it will take roughly two years until we start producing vehicles." It will take another two to three years for the factory to ramp up to a full 500,000 vehicles per year.

Of course, Tesla has a history of setting overly optimistic deadlines. At the end of June, Tesla finally reached a production rate of 5,000 vehicles per week in its Fremont factory, a milestone the company had previously aimed to reach at the end of 2017.

Industry analyst and dogged Tesla critic Ed Niedermeyer tweeted that "two years from zero to production is bonkers," noting that car companies traditionally take longer than that to build and begin operating a new factory.

So while Tesla may be aiming to start producing cars in China in 2020, we won't be surprised if the schedule slips by a year or two.