realXtend / tundra

realXtend Tundra SDK, a 3D virtual world application platform.
www.realxtend.org
Apache License 2.0
84 stars 70 forks source link

Investigate reducing/removing reliance on Qt and Boost #595

Closed peterclemenko closed 11 years ago

peterclemenko commented 11 years ago

With the Android version in development, it would be massively beneficial to cut down/remove heavier dependencies such as Boost and Qt. Implementing lighter weight code/external dependencies that have needed functionality would drastically cut down on memory usage, which will be critical to keep down for mobile devices.

This should involve determining where memory heavy dependencies such as Boost/Qt are used, and making them optional, rather than mandatory, by replacing functionality with much lighter weight alternatives where needed.

Stinkfist0 commented 11 years ago

Replacing Boost should be relatively easy by using the std::tr1 equivalents. AFAIK, the only problem would be boost::thread, which doesn't have equivalent in std::tr1, but own thread class could naturally be implemented. Removing Qt from the current Tundra codebase is not really feasible, but lessening the usage of it could be possible in theory at least by adding some lighter libraries such as libcurl and TinyXML for specific purposes to replace some of the Qt's modules.

juj commented 11 years ago

Step-by-step removing Boost is something we can consider. There's relatively little we need from it, and patches that work in small steps towards removing Boost are welcome. Additionally to what Stinkfist0 reported, we use Boost regex in a few places, which unfortunately is not supported in all compilers in their TR1 support.

Tundra is built primarily on MSVC9 (Visual Studio 2008 SP1), on Ubuntu Linux 12.10 with GCC 4.7.2 and on OSX with GCC 4.2.1. We don't build with Clang, but there's no particular reason for that.

For reference, the status of TR1 on different compilers: Visual Studio 2008 SP1 brought in support for std::tr1 on MSVC: http://support.microsoft.com/kb/950263 GCC TR1 status: http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.tr1 It doesn't say which version brought in TR1 support though. Clang support for TR1: http://clang.llvm.org/cxx_status.html The page says that the current (LLVM 3.1) version supports all features of the 2003 standard.

Removing Qt (QtCore) is not possible. Removing the use of individual Qt modules, like QtGui or QtScript is a possibility, which is exactly what the current Angelscript and librocket development branches are researching.

peterclemenko commented 11 years ago

Fair enough, my main concern with this issue being brought up is that because mobile devices have a limited amount of RAM to work with; slimming down RAM usage would improve battery life and improve performance.

Stinkfist0 commented 11 years ago

Little notes to self, in order to get rid of Boost: -introduce TUNDRA_NO_BOOST (or similar) definition for Boost opt-out -For Windows, VC10 or newer needed (VC9SP1 doesn't have make_shared f. ex.) -replace usage of boost::lexical_cast with own implementation, something similar to this f.ex. http://stackoverflow.com/a/8065539 -replace usage of boost::thread and boost::mutex with QThread and QMutex in Profiler and ShellInputThread -write replacement / find alternative for the boost::local_time::local_time_input_facet usage in HttpAssetProvider

peterclemenko commented 11 years ago

http://solarianprogrammer.com/2011/12/16/cpp-11-thread-tutorial/ http://solarianprogrammer.com/2012/02/27/cpp-11-thread-tutorial-part-2/ http://solarianprogrammer.com/2012/05/09/cpp-11-thread-tutorial-part-3/

http://solarianprogrammer.com/2012/10/17/cpp-11-async-tutorial/

If you are going to use C++11 as a requirement, you may as well use C++11 threading too. If you are going to use Qt, you should use qFuture: http://doc.qt.digia.com/qt/qfuture.html and qtConcurrent: http://doc.qt.digia.com/qt/threads-qtconcurrent.html

Also, regarding boost time related stuff, possibly use a c++11 regex to interpret localtime_s (on msvc) or localtime_r (on POSIX). It would require a bit of work, and possibly basing it off of the boost code, but it may help with cutting down the boost dependencies.

Stinkfist0 commented 11 years ago

As tempting as using the new C++11 features would be, I don't think it will be used in the Tundra codebase for a while until it's properly and somewhat fully supported by all of the major compilers.

jonnenauha commented 11 years ago

We cannot use C++11 in normal code as VC2008 (VC9) needs to be supported. It's our main dev env on windows. Bringing up VC2010 to the side is good but lets not jump to full c++11 land yet. The idea here was to use TR1 that is present in VC9 SP1 (afaik) to provide the needed "c++11" things and use the STL in other compilers.

We are using QThread in many places without problems and should port rest of the boost thread stuff to it. Seems like QFuture is more for small tasks not for all the time running threads (which is where we need threading most) so its not that useful. I think the main place to be ported out of boost thread is the console input reader, its easy to change to be QThread, a bit more code but doable. Also the pending command queue there could be replaces with Qt::QueuedConnection signal/slot connection to get the event to the main thread.

QFuture might be nice for asset cache disk i/o though, could start the operation and just at the last moment wait on the result. But for this to have any gains the assetapi flow would need to change a bit.

Stinkfist0 commented 11 years ago

FYI, my work continues in this branch https://github.com/LudoCraft/Tundra/tree/NoBoostVS2010

Stinkfist0 commented 11 years ago

Closing this now as Boost is no longer a mandatory dependency. New issues for researching removal of certain unimportant Qt modules from Tundra can be opened, but as Jukka said, removing Qt as a whole is not possible.