After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 731442 - bytereader: optimize _scan_for_start_code() using pointer access
bytereader: optimize _scan_for_start_code() using pointer access
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
git master
Other All
: Normal enhancement
: 1.3.3
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2014-06-10 08:23 UTC by Sungho Bae
Modified: 2014-06-11 00:06 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement


Attachments
001_gstbytereader_improved_by_pointer_access.patch (998 bytes, patch)
2014-06-10 08:23 UTC, Sungho Bae
committed Details | Review

Description Sungho Bae 2014-06-10 08:23:39 UTC
Created attachment 278185 [details] [review]
001_gstbytereader_improved_by_pointer_access.patch

This is a sub thread of the following:
https://bugzilla.gnome.org/show_bug.cgi?id=730783

Currently the scan uses Boyer-moore method and its performance is good.
but, it can be optimized from an implementation of view.

The original scan code is implemented by byte array and index-based access.
In _scan_for_start_code(), the index is increasing from start to end and the base address of the byte array is referred to as return value.

In the case, index-based access can be replaced by pointer access, which improve the performance by removing index-related operations.

Its performace is enhanced by approximately 8% on arm-based embedded devices.
Although it seems trivial, it can affect the overall performance because the _scan_for_start_code() function is very often called when H.264/H.265 video is played.

In addition, the technique can apply for all architectures and it is good in view of readability and maintainability.

I attached a patch file.

If you have a problem or question, let me know it.
After reviewing this, please apply it to git repository.
Comment 1 Edward Hervey 2014-06-10 08:39:02 UTC
Interesting. I would have expected the compiler to do that optimization.

Anyway, seems to also produce decent speedup on x86-64 (-O2) also.
Comment 2 Nicolas Dufresne (ndufresne) 2014-06-10 13:32:33 UTC
Review of attachment 278185 [details] [review]:

Looks good to me, I indeed thought the compiler was smarter.
Comment 3 Nicolas Dufresne (ndufresne) 2014-06-10 13:45:10 UTC
Comment on attachment 278185 [details] [review]
001_gstbytereader_improved_by_pointer_access.patch

commit d3b2f6e4b85a45213ed2878f411f7c66ebb15e33
Author: Sungho Bae <baver.bae@lge.com>
Date:   Tue Jun 10 09:35:38 2014 -0400

    bytereader: Use pointer instead of index access
    
    Currently the scan uses Boyer-moore method and its performance is good.
    but, it can be optimized from an implementation of view.
    
    The original scan code is implemented by byte array and index-based access.
    In _scan_for_start_code(), the index is increasing from start to end and the
    base address of the byte array is referred to as return value.
    
    In the case, index-based access can be replaced by pointer access, which
    improve the performance by removing index-related operations.
    
    Its performace is enhanced by approximately 8% on arm-based embedded devices.
    Although it seems trivial, it can affect the overall performance because the
    _scan_for_start_code() function is very often called when H.264/H.265 video is
    played.
    
    In addition, the technique can apply for all architectures and it is good in
    view of readability and maintainability.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=731442
Comment 4 Nicolas Dufresne (ndufresne) 2014-06-10 13:46:38 UTC
Thanks for you patch and time. It would be appreciated if you commit locally and use "git format-patch -1" next time. This will generate a patch with the commit log and author set correctly. It saves us a bit a time.
Comment 5 Sungho Bae 2014-06-11 00:06:16 UTC
(In reply to comment #1)
> Interesting. I would have expected the compiler to do that optimization.
> 
> Anyway, seems to also produce decent speedup on x86-64 (-O2) also.

I expected the compiler to do it. but, it hasn't yet supported.
Thanks for your interest and test on x86-64.


(In reply to comment #4)
> Thanks for you patch and time. It would be appreciated if you commit locally
> and use "git format-patch -1" next time. This will generate a patch with the
> commit log and author set correctly. It saves us a bit a time.

Thanks for your advice and review on my patch.
I will use "git format-patch -1" next time.