I imagine they must have spent masses on spaceflight capability which must have negatively impacted the economy in some ways. Or, did it indeed boost economy?
I've found some numbers in a leaflet Where the Soviet Cosmonautics is Going? (in Russian) by scientists Vsevolod Avduevsky and Leonid Leskov, published by Znanie All-Union Society in 1990. Avduevsky and Leskov's work is a pamphlet in defense of the Soviet cosmonautics, responding to unnamed but many-voiced critics "in the press, on television and even from the high rostrum [of the Congress of People's Deputies]": critics call for cutting down space expenses, claiming cosmonautics "lacking utility" for serving the national economy. The authors mention that the affairs of Soviet cosmonautics had been almost entirely shrouded in a thick veil of secrecy "until the recent years", comparing it to an iceberg with its bulk hidden underwater. Nonetheless, the changes that Gorbachev's Perestroika brought made it possible for the public to look at the space program and openly discuss and criticize it.
In 1989, the USSR allocated 6.9 billion rubles for space programs, including 3.9 billion for military and scientific purposes and 1.7 billion for applied programs contributing to the national economy, respectively. 1.3 billion rubles was spent on the Buran program. These figures speak for themselves: it is clear that that widely criticized multi-billion spending on civilian space activities is a myth: they account for only 0.26% of the national income. To make a comparison, this is 10 times smaller than the entire spending of the Ministry of Land Reclamation and Water Management, and 5 times smaller than foreign aid given by the USSR to other countries in the same year 1989.
(The total state budget revenues of the Soviet Union in 1989 were 469 billion rubles. Source: State Budget of the USSR 1989: Brief Statistics Digest, in Russian)
Avduevsky and Leskov argue that the space programs (at least, applied ones) actually bring money to the economy rather than losing them: the economic effect of Orbita, Ekran and Moskva satellite communications systems, as well as weather, remote sensing and mapping satellites accounted for 2 billion rubles of budget savings, over and above the spending of 1.7 billion rubles for these programs.
In the same year 1989, USSR declassified the documents on the unsuccessful N1 rocket, the superheavy launch vehicle that would have been the Soviet Union's counterpart to the Saturn V. Avuevsky and Leskov argue that the decision to discontinue the N1 program in 1974 was rushed and ill-considered, essentially wasting 2.5 billion rubles spent on the N1 development back in 1960s. As a result, N1's successor, the Energia rocket, had to be developed from scratch. Avduevsky and Leskov compare the decision to pull the plug on the N1 program with the construction of the infamous Krasnoyarsk radar station Yeniseysk-15, a painfully expensive military installation that was doomed from the very beginning. It was demolished the same year 1989 for being a breach of the 1972 Anti-Ballistic Missile Treaty.
The Energia, together with the Buran reusable spacecraft, was the most expensive space project in the history of Soviet space, still being much less expensive than the United States' Space Shuttle program. According to Avduevsky and Leskov, the development of the Energia alone costed 13 billion rubles, and the Buran spacecraft was just as costly: 1.3 billion rubles was spent on it in 1989, in spite of the fact that this counterpart to the Space Shuttle had not made a single space flight in 1989. The authors hoped that the Energia and Buran system would bring dramatic change to near space exploration in the years to come (which haven't happened), but argued that there could be cheaper alternatives to both the Buran and Space Shuttle, such as German Saenger project.
The estimated cost of the Soviet space programs for the next three five-year plans (until 2005) was 40 billion rubles, according to a publication of Glavkosmos space agency "USSR in Space. 2005" (also cited by Avduevsky and Leskov). That massive spending was to be covered by benefits brought in by satellite systems alone; it was just the space agency's estimate, not yet (and never) approved by the Supreme Soviet.
To answer the original question: the USSR was spending only a small fraction of its yearly budget on space programs. There were many things that shattered the Soviet economy by the end of 1980s; space exploration, as costly as it was, was unlikely to play a critical role.
Edit: 0.26% of the national income, not the national budget.