Bug 161058 - bmalloc: speed up the lock slow path
Summary: bmalloc: speed up the lock slow path
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Geoffrey Garen
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-08-22 14:33 PDT by Geoffrey Garen
Modified: 2016-08-30 17:17 PDT (History)
7 users (show)

See Also:


Attachments
Patch (16.99 KB, patch)
2016-08-22 15:19 PDT, Geoffrey Garen
fpizlo: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Geoffrey Garen 2016-08-22 14:33:13 PDT
bmalloc: speed up the lock slow path
Comment 1 Geoffrey Garen 2016-08-22 15:19:55 PDT
Created attachment 286629 [details]
Patch
Comment 2 WebKit Commit Bot 2016-08-22 15:21:04 PDT
Attachment 286629 [details] did not pass style-queue:


ERROR: Source/bmalloc/bmalloc/StaticMutex.cpp:26:  Found other header before WebCore config.h. Should be: config.h, primary header, blank line, and then alphabetically sorted.  [build/include_order] [4]
ERROR: Source/bmalloc/bmalloc/StaticMutex.cpp:40:  More than one command on the same line  [whitespace/newline] [4]
Total errors found: 2 in 6 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Filip Pizlo 2016-08-22 15:23:19 PDT
Comment on attachment 286629 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=286629&action=review

> Source/bmalloc/ChangeLog:26
> +        To correct these problems, this patch adds a little bit of spinning to
> +        the bmalloc lock slow path.

Nice.

> Source/bmalloc/bmalloc/StaticMutex.cpp:40
> +        auto clear = makeScopeExit([&] { m_isSpinning.clear(); });

LOL.  I can't make up my mind if this is awesome or confusing.

> Source/bmalloc/bmalloc/ThreadSwitch.h:38
> +    swtch();

What is this?
Comment 4 Geoffrey Garen 2016-08-22 16:12:05 PDT
> > Source/bmalloc/bmalloc/StaticMutex.cpp:40
> > +        auto clear = makeScopeExit([&] { m_isSpinning.clear(); });
> 
> LOL.  I can't make up my mind if this is awesome or confusing.

I kinda like it -- similar to the defer keyword in Go and Swift. The other option I considered was a "TestAndSetScope" class, which would clear() in its destructor if it had set in its constructor.

> > Source/bmalloc/bmalloc/ThreadSwitch.h:38
> > +    swtch();
> 
> What is this?

Documented here: https://www.gnu.org/software/hurd/gnumach-doc/Hand_002dOff-Scheduling.html.

My reading of the implementation is that it just runs the "find another thread to run" algorithm, without changing your priority or power management or anything.
Comment 5 Geoffrey Garen 2016-08-22 16:19:50 PDT
Committed r204744: <http://trac.webkit.org/changeset/204744>
Comment 6 Yusuke Suzuki 2016-08-22 17:44:58 PDT
Committed r204749: <http://trac.webkit.org/changeset/204749>
Comment 7 Ryosuke Niwa 2016-08-23 23:03:44 PDT
This appears to be ~6% progression on Dromaeo DOM Core bench on MacBookAirs.
Comment 8 Geoffrey Garen 2016-08-24 10:54:26 PDT
On Speedometer, I also see a ~4% progression on MacBook Air and a ~2% progression on MacBook Pro.
Comment 9 Geoffrey Garen 2016-08-25 16:48:44 PDT
I can't seem to reproduce a Dromaeo DOM Core or Speedometer speedup locally on my MacBook Air. (I see a fraction of a % speedup or no change. I didn't compute a confident interval.)
Comment 10 Gavin Barraclough 2016-08-26 10:05:18 PDT
Rolled out in https://trac.webkit.org/changeset/205022
Comment 11 Geoffrey Garen 2016-08-30 17:17:40 PDT
Committed r205210: <http://trac.webkit.org/changeset/205210>