Sinopec’s profit inched higher in the first half, after an improved performance from upstream operations offset the impact of a slowing Chinese economy and hefty declines in the company’s main businesses of processing and selling fuels.

Net income in the first six months rose 1.7% on year to 35.7 billion yuan ($5 billion) on revenue of 1.58 trillion yuan, a 1.1% decline, according to earnings on Sunday from the company formally known as China Petroleum and Chemical Corp.. But there were bigger swings at the operating profit level that give a better sense of the challenges facing China’s largest oil refiner.

While exploration and production rose 15% over the period, helped by stronger international crude prices and gains in output, there were drops of 38% in oil processing and 14% in marketing and distribution. Diesel, used in construction, was particularly weak. The state-owned company’s chemicals business remained in the red although losses narrowed.

Crude refining is one of China’s worst-performing industries, according to the statistics bureau, with accumulated losses in the first half of the year stretching to 16 billion yuan ($2.2 billion). Higher prices and rising transport costs related to conflict in the Red Sea have been a drag.

But much of the decline is long-term and linked to the energy transition as electric vehicles and gas-fueled trucks sap consumption of gasoline, which makes up about a quarter of the domestic oil market. Diesel demand is faltering because of China’s protracted property crisis, while capacity expansions amid the broader economic slowdown have created a glut of petrochemicals.

Sinopec’s vast refining operations leave it more heavily affected by the ups and downs of China’s industrial and retail consumption, unlike its more upstream-focused state rivals. PetroChina Co. releases earnings later Monday after a strong first quarter, while Cnooc Ltd.’s report is on Wednesday.

Sinopec’s stock rose as much as 1.8% in Hong Kong after its earnings met estimates. The company was sanguine about the second-half outlook and expects further improvement in China’s economy and demand growth in both natural gas and chemicals, according to its statement. It also plans to keep oil processing and product sales in the second half at around the same levels as the first, although that’ll include less diesel.