Image handling rework for LibreOffice – Collabora’s tender results

Donations to The Document Foundation are used for many purposes, such as organising events, maintaining our infrastructure, and paying a small team to handle QA, marketing, documentation and other tasks. But donations are also used to fund tenders, whereby companies and individuals improve LibreOffice in specific areas and share knowledge with the community.

One such tender was posted in May 2017: “improve image handling in LibreOffice (#201705-01)“. When images are used in LibreOffice documents, the software manages them in a “life-cycle” which includes importing, displaying, modifying, exporting and more. To save memory – especially with large documents – images that are not currently on screen are sometimes moved out of memory and saved onto disk in a technique known as “swapping” or “paging”. The goal of the tender was to improve LibreOffice in these areas, making it more efficient at handling images and modernising the code base.

Collabora was selected to implement the tender; the work is now complete, and it will benefit all users in the upcoming LibreOffice 6.1 (due to be released in early August). Here are some technical notes about what was improved in the source code of LibreOffice, and what was achieved.

Problems with the image life-cycle

Currently, when an image is read from a document, a GraphicObject is created for the image and handled over to the GraphicManager which manages the life-cycle. When this happens we usually get back the string based unique ID of the GraphicObject with which we can always get access the image by creating a new GraphicObject with the unique ID (GraphicManager will look for the image with that unique ID).

Usually the unique ID is the one that is passed on between layers in LibreOffice (for example, from the ODF filter when loaded, to the model, where it is manipulated and then to the OOXML filter when saving) but the unique ID itself is just a “reference” to the image and by itself it doesn’t have any control over when the image can safely be removed and when not. It could happen that in a certain situation we would still have the unique ID referenced somewhere in the model, but the image would already be removed. This is dangerous and needs to be changed.

Usually for this kind of object we use a reference counting technique, where we pass an object around that holds a reference to the object resource. When the object is created, the reference count is increased; when destroyed, the reference count is decreased; when the reference count reaches zero, the resource object is destroyed.

The solution for the life-cycle

So instead of passing around a unique ID, the idea is to use the usual reference counting technique, which is normally used in this situation. The GraphicObject is mainly a wrapper around Graphic (which then holds a pixel-based image, or animated image, or possibly a vector image), and in addition it keeps additional attributes (gamma, crop, transparency etc.). It also has the implementation of swapping-in and out.

On the other hand, Graphic is properly reference-counted already (Graphic objects are reference counting the private ImpGraphic) so the solution to the life-cycle problem is that instead of GraphicObject unique ID, we would just pass along the Graphic object instead, or XGraphic, XBitmap which are just UNO wrappers around Graphic. Potentially we could also pass along the GraphicObject or XGraphicObject (UNO wrapper for the GraphicObject) when we would need to take into account the graphic attributes too. This should make the life-cycle much more manageable.

GraphicObject refactoring

GraphicObject and the implementation of XGraphicObject (UnoGraphicObject) and XGraphic (UnoGraphic) were located in module svtools, which is hierarchically above vcl. This is problematic when creating new instances like in Graphic.GetXGraphic method, which needs to bend backward to make it even work (ugly hack by sending the pointer value as URL string to GraphicProvider). The solution to this is to move all GraphicObject related things to vcl, which surprisingly didn’t cause a lot problem and once done, it looks like a much more “natural” place.

Managing memory used by images

Previously, the memory managing was done on the level of GraphicObjects, where a GraphicManager and Graphic-Cache were responsible to create new instances from uniqueID and manage the memory usage that GraphicObject take. Here’s the hierarchy before refactoring:

This is not possible anymore as we don’t operate with uniqueIDs anymore, but always use Graphic and XGraphic objects (in UNO), so we need to manage the creation of Graphic object or more precisely – ImpGraphic (Graphic objects are just reference-counted objects of ImpGraphic).

So to make this possible GraphicManager and GraphicCache need to be decoupled and removed from GraphicObject and a new manager needs to be introduced between Graphic and ImpGraphic, where the manager controls the creation and accounts for the memory usage:

Graphic swapping and swapping strategy

The new swapping strategy is relatively simple – if a lot of memory is needed by graphic objects in a certain time, we let it use it and don’t try to over-aggressively try to free it. In the past this cased swap-out and swap-in cycle that made the application completely unusable. In the future, external hints when a certain Graphic object can be swapped out may be added, so we can perform swapping more effectively. There are also several other ideas which will increase performance and reduce memory usage that can be implemented now with the new hierarchy where most all of the swapping is contained inside the Graphic itself, but all of this is currently out of the scope of this work.

In conclusion

Thanks to Collabora and Tomaž Vajngerl for their work on this. Although the details are highly technical, the end result is a faster and more robust office suite. If you’re an end user of LibreOffice and your documents include lots of images, you will be able to enjoy the benefits of this work in future releases, starting with LibreOffice 6.1.

Final week of the Month of LibreOffice, May 2018

At the start of this month, we kicked off a new Month of LibreOffice, celebrating contributions all across the project! So how many stickers have been won so far? Well…

To see if your name (or username) is on the list, click the number above. If you’re not there, there’s still time to get involved! There are many ways you can help the LibreOffice project and claim a sticker:

  • Help to confirm bugs: go to our Bugzilla page and look for new bugs. If you can recreate one, add a comment like “CONFIRMED on Windows 10 and LibreOffice 5.4.6”. (Make sure you’re using the latest version of LibreOffice.)
  • Contribute code: The codebase is big, but there are lots of places to get involved with small jobs. See our Developers page on the website and this page on the wiki to get started. Once you’ve submitted a patch, if it gets merged we’ll send you a sticker!
  • Translate the interface: LibreOffice is available in a wide range of languages, but its interface translations need to be kept up-to-date. Or maybe you want to translate the suite to a whole new language? Get involved here.
  • Write documentation: Another way to earn a badge is to help the LibreOffice documentation team. Whether you want to update the online help or add chapters to the handbooks, here’s where to start.
  • Answer questions from users: Over on Ask LibreOffice there are many users looking for help with the suite. We’re keeping an eye on that site so if you give someone useful advice, you can claim a shiny sticker.
  • Spread the word: Tell everyone about LibreOffice on Twitter! Just say why you love it or what you’re using it for, add the #libreoffice hashtag, and at the end of the month you can claim a sticker. (We have a maximum of 100 stickers for this category, in case the whole internet starts tweeting!)

So don’t miss out! There’s one week to go – help other users, update our documentation, translate the software and help to make LibreOffice better for millions of users around the world!

Please confirm that you want to play a YouTube video. By accepting, you will be accessing content from YouTube, a service provided by an external third party.

YouTube privacy policy

If you accept this notice, your choice will be saved and the page will refresh.

Coming up on May 28: Bug Hunting Session for LibreOffice 6.1 Beta 1

LibreOffice 6.1 is being developed by our worldwide community, and is due to be released in early August – see the release notes describing the new features here. You can help us to test it, and make it super reliable!

After the first Bug Hunting Session for LibreOffice 6.1, which was held on April 27th 2018, we’re glad to announce the Second Bug Hunting Session on May 28th – this time being held on a Monday.

In order to find, report and triage bugs, the tests during the Second Bug Hunting Session will be performed on the first Beta version of LibreOffice 6.1, which will be available on the pre-releases server on the day of the event. Builds will be available for Linux (DEB and RPM), macOS and Windows, and can be run in parallel with the production version – so you can test without affecting your existing stable installation.

Mentors will be available on May 28th 2018, from 8AM UTC to 8PM UTC for questions or help in the IRC channel: #libreoffice-qa and its Telegram bridge. Of course, hunting bugs will be possible also on other days, as the builds of this particular Beta release (LibreOffice 6.1.0 Beta1) will be available until the beginning of July.

During the day there will be two dedicated sessions focus on two of the tenders implemented in LibreOffice 6.1: The first to test the improvements on the image handling between 10AM UTC and 12AM UTC, and the second to test the HSQLDB import filter for firebird between 14PM UTC and 16PM UTC.

What happened during the first Bug Hunting Session ?

Since LibreOffice 6.1 Alpha 1 was released on week 17 of 2018, 91 bugs have been reported against Alpha 1 by more than 30 people, of which 26 have been already closed.

In total, 8 of these bugs have been categorized as critical, and 4 already fixed by the development team.

Base and Writer are the components with more reports, both having 18 each.

Many thanks to the top 5 reporters: Drew Jensen, Emil Tanev, Xisco Faulí, Telesto and Pander.

So join us on Monday, and we look forward to – and appreciate – your help!

LibreOffice and VolunteerMatch: Welcoming new contributors

Free and open source software, such as LibreOffice, is all about community. Anyone can get involved, and many people join the LibreOffice community because they want to improve something in the software – features, compatibility, translations, documentation, marketing and more. As we’ve seen in the ongoing Month of LibreOffice, we have hundreds of volunteers active in making the software better.

But new volunteers are always welcome! And we try to reach out to as many people as possible. So we’ve set up a page on VolunteerMatch, a US-based non-profit organisation that “connects millions of people with a great place to volunteer”. Our page currently shows six opportunities to get involved with LibreOffice, including development, user interface, marketing, documentation and QA (quality assurance).

If you use LibreOffice and want to help improve it, check out the opportunities – or let us know if we should add more. And please help us to spread the word, so that we can continue to grow our community and bring in new volunteers. Thank you!

Share on Facebook | Share on Twitter | Share on Google+ | Share on LinkedIn

(Thanks to Ilmari Lauhakangas for his help.)

Month of LibreOffice, May 2018 – The first week in

On May 1st, we started a new Month of LibreOffice, celebrating contributions all across the project. Everyone who gets involved will be awarded a cool sticker for their work – so how many stickers have been won so far?

So that’s almost 150 community members who’ve helped to improve LibreOffice in the last week alone! Click the number above to see if your name (or username) is on the list. And if you’re not there, now’s the time to get involved! There are many ways you can help the LibreOffice project and claim a sticker – and join our friendly community as well:

How to get a sticker

  • Help to confirm bugs: go to our Bugzilla page and look for new bugs. If you can recreate one, add a comment like “CONFIRMED on Windows 10 and LibreOffice 5.4.6”. (Make sure you’re using the latest version of LibreOffice.)
  • Contribute code: The codebase is big, but there are lots of places to get involved with small jobs. See our Developers page on the website and this page on the wiki to get started. Once you’ve submitted a patch, if it gets merged we’ll send you a sticker!
  • Translate the interface: LibreOffice is available in a wide range of languages, but its interface translations need to be kept up-to-date. Or maybe you want to translate the suite to a whole new language? Get involved here.
  • Write documentation: Another way to earn a badge is to help the LibreOffice documentation team. Whether you want to update the online help or add chapters to the handbooks, here’s where to start.
  • Answer questions from users: Over on Ask LibreOffice there are many users looking for help with the suite. We’re keeping an eye on that site so if you give someone useful advice, you can claim a shiny sticker.
  • Spread the word: Tell everyone about LibreOffice on Twitter! Just say why you love it or what you’re using it for, add the #libreoffice hashtag, and at the end of the month you can claim a sticker. (We have a maximum of 100 stickers for this category, in case the whole internet starts tweeting!)

So join us! We’ll be awarding stickers throughout the whole month, and then posting them in June. See this video for more info:

Please confirm that you want to play a YouTube video. By accepting, you will be accessing content from YouTube, a service provided by an external third party.

YouTube privacy policy

If you accept this notice, your choice will be saved and the page will refresh.