Merge lp://staging/~aacid/thumbnailer/fast_string_concatenation into lp://staging/thumbnailer/devel

Proposed by Albert Astals Cid
Status: Rejected
Rejected by: Albert Astals Cid
Proposed branch: lp://staging/~aacid/thumbnailer/fast_string_concatenation
Merge into: lp://staging/thumbnailer/devel
Diff against target: 154 lines (+16/-13)
7 files modified
CMakeLists.txt (+3/-0)
src/thumbnailer-admin/clear.cpp (+3/-3)
src/thumbnailer-admin/get_local_thumbnail.cpp (+1/-1)
src/thumbnailer-admin/get_remote_thumbnail.cpp (+2/-2)
src/thumbnailer-admin/show_stats.cpp (+3/-3)
src/thumbnailer-admin/shutdown.cpp (+2/-2)
src/thumbnailer-admin/thumbnailer-admin.cpp (+2/-2)
To merge this branch: bzr merge lp://staging/~aacid/thumbnailer/fast_string_concatenation
Reviewer Review Type Date Requested Status
Albert Astals Cid (community) Disapprove
Michi Henning (community) Needs Information
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+272935@code.staging.launchpad.net

Commit message

Enable Efficient String Construction by default

See http://blog.qt.io/blog/2011/06/13/string-concatenation-with-qstringbuilder/

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
288. By Albert Astals Cid

Trhow QString instead of QStringBuilder

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michi Henning (michihenning) wrote :

I'm feeling a bit ambivalent about this change now. The original change picked up by the tool was:

- string inpath = (artist_ + "_" + album_).toStdString() + "_" + suffix;
+ string inpath = QString(artist_ + "_" + album_).toStdString() + "_" + suffix;

Fair enough, it's a little bit more efficient this way. But, in practice, it doesn't make one iota of difference because the cost of the string catenation is infinitesimal compared to the overall cost of the operation. (We are about to do a client-server round trip.)

And now we have all the other changes where the cast to QString is needed. I'm wondering whether that really is worth it. We have more cryptic code in quite a few places now, in return for a performance improvement that is immeasurably small. Is this the right trade-off?

review: Needs Information
Revision history for this message
Albert Astals Cid (aacid) wrote :

It is not always about speed but also less allocations happening meaning the memory gets less fragmented which is as well interesting for long lived apps.

As for wheter

- string inpath = (artist_ + "_" + album_).toStdString() + "_" + suffix;
+ string inpath = QString(artist_ + "_" + album_).toStdString() + "_" + suffix;

is more readable or not i guess it's up to you, but it adds some more explicitness, meaning readers that are not the ones that immediately wrote the code know that the toStdString is being called over a QString and don't have to guess the types of artist_ and album_ check if they are the same and then check the operator + with "_" still gives the same type.

Revision history for this message
Michi Henning (michihenning) wrote :

Well, sure, I agree with the memory fragmentation in principle. But, let's face it, this just isn't going to make any noticeable difference. There are dozens (if not more) allocations elsewhere for each request.

What I find worrying here is are all the other changes, such as this one:

- throw parser.errorText() + "\n\n" + parser.helpText();
+ throw QString(parser.errorText() + "\n\n" + parser.helpText());

Adding the -DQT_USE_QSTRINGBUILDER caused previously working code to fail because, suddenly, what is thrown is a string builder instead of a string. I can't say I like this magic all that much. The same single expression (a + b) can return two different types, depending on whether the symbol is defined or not.

A less intrusive change would be to not do all the casts where the exceptions are thrown and instead add a catch handler for string builder in main? But, even then, this leaves a bad taste in my mouth. Changing the type of an expression via a preprocessor symbol is dangerously close to preprocessor abuse, IMO.

Revision history for this message
Albert Astals Cid (aacid) wrote :

Michi doesn't like the change

review: Disapprove

Unmerged revisions

288. By Albert Astals Cid

Trhow QString instead of QStringBuilder

287. By Albert Astals Cid

Enable Efficient String Construction by default

See http://blog.qt.io/blog/2011/06/13/string-concatenation-with-qstringbuilder/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches

to all changes: