Thread: [Cppcms-users] About raw filter translation.
Brought to you by:
artyom-beilis
From: redred77 <red...@gm...> - 2015-07-04 17:09:22
|
Hi It seems like raw filter in view template does nothing but just wraps input variable. So below two lines are just same. out()<<cppcms::filters::raw(content.hello); out()<<content.hello; First one looks more structured which seems like to follow rules like other filters. But isn't it better for cppcms_tmpl_cc.py to translate like the second one in a performance aspect view? I know CppCMS is fast enough but don't want to waste CPU cycle for these reasons. 1. This logic is not necessary at all. 2. Translated result cpp is not intended to view or edit for human. It can be optimized more. 3. I use raw filter far many times. More than escape filter. 4. Maybe I'm too obsessed with performance I think I can edit the cppcms_tmpl_cc.py code to change behaviour and send patch but want to listen thoughts about it. Thanks. |
From: Joerg S. <jo...@br...> - 2015-07-04 20:06:12
|
On Sun, Jul 05, 2015 at 02:09:16AM +0900, redred77 wrote: > It seems like raw filter in view template does nothing but just wraps input > variable. > So below two lines are just same. > > out()<<cppcms::filters::raw(content.hello); > out()<<content.hello; > > First one looks more structured which seems like to follow rules like other > filters. > But isn't it better for cppcms_tmpl_cc.py to translate like the second one > in a performance aspect view? It's inlined. Joerg |
From: redred77 <red...@gm...> - 2015-07-05 04:32:09
|
I think you over trusted compiler's inline function. They do their best, but they can't skip making temporary objects. 1. So, I benchmarked. Printed 1000000 times for each and measured with Windows QueryPerformanceCounter(). Of course compiled for Release build. (Full Optimization) out() << "/testtext"; out() << cppcms::filters::raw("/testtext"); Result : 0.109707 sec 0.120335 sec So filters::raw() is actually slower about 9%. 2. You'll be surprised when you see the disassembly. out() << "/testtext"; 00FDC828 mov ecx,ebx 00FDC82A call edi 00FDC82C mov edx,1026F50h 00FDC831 mov ecx,eax 00FDC833 call std::operator<<<std::char_traits<char> > (0FD1A30h) out() << cppcms::filters::raw("/testtext"); 00FDC838 push 1026F50h 00FDC83D lea ecx,[esp+50h] 00FDC841 call dword ptr ds:[10131D8h] 00FDC847 lea eax,[esp+4Ch] 00FDC84B mov dword ptr [esp+0D0h],2 00FDC856 push eax 00FDC857 lea ecx,[esp+2Ch] 00FDC85B call dword ptr ds:[10131CCh] 00FDC861 mov esi,eax 00FDC863 mov ecx,ebx 00FDC865 mov byte ptr [esp+0D0h],3 00FDC86D call edi 00FDC86F push eax 00FDC870 mov ecx,esi 00FDC872 call dword ptr ds:[10131D4h] 00FDC878 lea ecx,[esp+28h] 00FDC87C mov byte ptr [esp+0D0h],2 00FDC884 call dword ptr ds:[10131D0h] 00FDC88A lea ecx,[esp+4Ch] 00FDC88E mov dword ptr [esp+0D0h],0FFFFFFFFh 00FDC899 call dword ptr ds:[10131E0h] There's so many call instructions that are actually not necessary at all. It's because wrapping with filters::raw is not just call and return but it makes and destroy temporary streamable object each time. Here are brief call order. You can also follow this codes one by one with your debugger. streamable::streamable(char const *ptr) streamable::streamable(streamable const &other) raw::raw(streamable const &obj) : obj_(obj) {} inline std::ostream &operator<<(std::ostream &out,raw const &obj) void raw::operator()(std::ostream &out) const void streamable::operator()(std::ostream &out) const void ch_to_stream(std::ostream &out,void const *p) 3. What I like and decided to move to CppCMS the most is that it takes performance seriously. Maybe I'm too concerned about performance, but this is what I learned from the server running currently. It crashed down so many times when visitors explode. Thanks. 2015-07-05 5:06 GMT+09:00 Joerg Sonnenberger <jo...@br...>: > On Sun, Jul 05, 2015 at 02:09:16AM +0900, redred77 wrote: > > It seems like raw filter in view template does nothing but just wraps > input > > variable. > > So below two lines are just same. > > > > out()<<cppcms::filters::raw(content.hello); > > out()<<content.hello; > > > > First one looks more structured which seems like to follow rules like > other > > filters. > > But isn't it better for cppcms_tmpl_cc.py to translate like the second > one > > in a performance aspect view? > > It's inlined. > > Joerg > > > ------------------------------------------------------------------------------ > Don't Limit Your Business. Reach for the Cloud. > GigeNET's Cloud Solutions provide you with the tools and support that > you need to offload your IT needs and focus on growing your business. > Configured For All Businesses. Start Your Cloud Today. > https://www.gigenetcloud.com/ > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |
From: Joerg S. <jo...@br...> - 2015-07-05 09:26:17
|
On Sun, Jul 05, 2015 at 01:32:02PM +0900, redred77 wrote: > I think you over trusted compiler's inline function. > They do their best, but they can't skip making temporary objects. Well, the temporary object is a slightly different question. That's a result of the out-of-line definition. Why it is forcing that only Artyom can answer. Joerg |