This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [Patch] Optimize _BFSExecutor in regex
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Tim Shen <timshen91 at gmail dot com>
- Cc: "libstdc++" <libstdc++ at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 8 Oct 2013 00:11:55 +0100
- Subject: Re: [Patch] Optimize _BFSExecutor in regex
- Authentication-results: sourceware.org; auth=none
- References: <CAPrifDkH0sC3FwfUrWC4Nb3h6GYsCUTvdmrgf_+UN1ZfmJwrsw at mail dot gmail dot com> <CAH6eHdQjKNAzLXCoA07T7tB5HfExEFN8rCBayvP=GCS1_=BiPg at mail dot gmail dot com> <CAPrifDko9SnheJ+aQ45W5NLyK5NKHfP_-3f0pczROiXCKf8bDg at mail dot gmail dot com> <CAH6eHdS0B6wpXQdhXTbXo1PgjnuUSjfoAbK404VE+MPAya48FQ at mail dot gmail dot com> <CAPrifDk6R9wtoZNewyNpESgkx1J6YW0xJNaut0tG-ta5RJ3p+w at mail dot gmail dot com> <CAH6eHdS81ftVScJW_zhxt=gW=2g60fnHA=0O70AQr0jpB-m4ug at mail dot gmail dot com> <CAPrifDndETV=aU82C9BB0rZv=VQRwU36WxWzM09raHEoQ8gXHA at mail dot gmail dot com> <CAH6eHdQv-fyiz2mSzOgh5EhokSKxRrbUuVvFe161Wt2+3_BNvQ at mail dot gmail dot com> <CAPrifD=VVgG9oicJR-fAALJs_sp7MfNU8JcA83VciKpb35PpVA at mail dot gmail dot com>
On 7 October 2013 22:14, Tim Shen wrote:
> On Mon, Oct 7, 2013 at 1:28 PM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
>> std::memset() on about 125 bytes is not a big deal, I doubt it's
>> significantly more expensive than the calculations to find the right
>> bits and do the necessary masking for three elements.
>> std::vector<bool> is a strange beast, remember.
>
> Probably there could be bitwise operation?
Yes, most operations on vector<bool> involve bitwise operations.
> I've test the 3 trues out of 1000 elements here :
> https://gist.github.com/innocentim/6874889
> In my machine, choosing "v.assign(v.size(), false);" cost 1.768s and
> choosing the other cost 1.088s. When we push 7 elements, they cost
> almost same time. When push more than that, v.assign() shall win.
You're right, popping one at a time is measurably faster than filling
the whole vector<bool> with zeros, even when _M_exists.size() is
small. I'm quite surprised. I expected updating the vector size on
every pop_back() to make it slower.
The version in your gist (which is *not* what your first patch did!)
is faster for any size of _M_exists and any ratio of _M_states.size()
/ _M_exists.size():
> I do this because I need to use _M_clear() in this patch :)
>
> Anyway let's use v.assign().
Sorry for wasting your time regarding using assign(), it does seem to
be slower (and produces larger code) so please go for something like
in your gist (not in the original patch, which left true values in the
_M_exists vector!) i.e. something like
for (auto __i : _M_states)
_M_base[__i] = false;
_M_base.clear();
But please rename _M_base, that name doesn't make sense, it used to be
the base class, but it isn't now, and that vector has nothing to do
with base classes now! How about _M_states?
Please also make _M_empty() const.
Thanks!