Archive for January 30, 2017

Monday, January 30, 2017

Riptide: WebKit’s Retreating Wavefront Concurrent Garbage Collector

Filip Pizlo:

As of r209827, 64-bit ARM and x86 WebKit ports use a new garbage collector called Riptide. Riptide reduces worst-case pause times by allowing the app to run concurrently to the collector. This can make a big difference for responsiveness since garbage collection can easily take 10 ms or more, even on fast hardware. Riptide improves WebKit’s performance on the JetStream/splay-latency test by 5x, which leads to a 5% improvement on JetStream. Riptide also improves our Octane performance.

[…]

WebKit uses a simple segregated storage heap structure. The DOM, the Objective-C API, the type inference runtime, and the compilers all introduce custom marking constraints, which the GC executes to fixpoint. Marking is done in parallel to maximize throughput. Generational collection is important, so WebKit implements it using sticky mark bits. The collector uses conservative stack scanning to ease integration with the rest of WebKit.

[…]

Draining in parallel means having to synchronize marking. Our marking algorithm uses a lock-free CAS (atomic compare-and-swap instruction) loop to set mark bits.

[…]

Our collector does not move objects. Instead, it uses the mark bit to also track generation. Quite simply, we don’t clear any mark bits at the start of an eden collection. The marking algorithm will already ignore objects that have their mark bits set. This is called sticky mark bit generational garbage collection.

[…]

Riptide is able to stop the world for certain tricky operations like stack scanning and DOM constraint solving.

Riptide uses a retreating wavefront write barrier to manage races between marking and object mutation. Using retreating wavefront allows us to avoid any impedance mismatch between generational and concurrent collector optimizations.

Facebook Accepts Slightly Mis-typed Passwords

Interesting threads on Hacker News and Stack Overflow. It sounds like Facebook accepts different variations on your password, and it also warns if your new password is too similar to your old one. In both cases, this is done by generating strings (e.g. with different case or the last character removed) based on what you typed. Only the hash of the actual password is stored.

Take Control of Your Digital Legacy

Joe Kissell:

In the customer survey Take Control Books conducted a few months ago, the topic of one’s digital legacy was the most popular by a large margin. People are increasingly concerned about what will happen to their accounts, email, photos, and other data if they die or become incapacitated; and beyond that, how they can make sure all (and only) the data they want to pass down to future generations is preserved in a way that will still be useful decades or centuries from now. I tackle all these subjects, and more, in Take Control of Your Digital Legacy.

Update (2017-01-31): Joe Kissell:

To introduce the book to you, I’ve framed a number of the questions that prompted the book, and their answers, as a conversation with my completely imaginary Aunt Agatha.

Processing the Selected Text via Script

It seems like it should be easy to run the selected text in any app through a shell script, but I’ve run into a surprising number of issues doing this. I’ve long used ThisService to create system services out of shell scripts that sort lines, smarten quotes, and apply title case. Then I would assign keyboard shortcuts in System Preferences and have easy access to the scripts from any app.

Over the last few months, keyboard shortcuts for system services (and PDF services) have become unreliable. They still show up in System Preferences, but they usually don’t work. Often, System Preferences forgets them. It also forgets which services I’ve enabled and disabled, hiding my favorite scripts and bringing back dozens of commands that I never use. This makes the Services contextual menu unwieldy. The Keyboard preferences pane is awkward to use, so that it takes a long time to go through the list checking and unchecking the appropriate boxes.

My first thought was to use LaunchBar, which I knew could get and replace the selected text (either using a script or a service). However, this takes multiple steps: long Command-Space to load the text, Tab, type the name of the script/service, Command-Shift-C to copy the result text and paste it back. This is fine for occasionally used scripts, where keyboard shortcuts would not be practical, but not for ones I use many times per day.

How about using FastScripts to assign keyboard shortcuts and run the scripts? Unfortunately, most applications are not scriptable enough to access the selected text. I wrote a script to use GUI scripting to invoke my service from the Services menu:

my runServiceNamed("Title Case")

on runServiceNamed(_serviceName)
    tell application "System Events"
        set _frontApp to first application process whose frontmost is true
        tell _frontApp
            set _appMenu to menu 2 of menu bar 1
            set _servicesMenu to menu 1 of menu item "Services" of _appMenu
            set _menuItem to menu item _serviceName of _servicesMenu
            click _menuItem
        end tell
    end tell
end runServiceNamed

However, GUI scripting the menu bar doesn’t seem to work in MarsEdit, one of the apps where I would use the scripts most frequently.

I ended up giving up on services entirely and used GUI scripting and the clipboard to get and set the selected text:

my process("/Users/mjt/Library/Application Support/BBEdit/Text Filters/titlecase.py")

on process(_scriptPath)
    set _savedClipboard to the clipboard

    -- Copy selected text
    tell application "System Events" to keystroke "c" using {command down}
    delay 1 -- Without this, the clipboard may have stale data.

    -- Clipboard has Mac line breaks, but script requires Unix.
    set _script to "pbpaste | tr '\\r' '\\n'  | " & _scriptPath's quoted form & " | pbcopy"
    do shell script _script

    -- Paste to replace selected text
    tell application "System Events" to keystroke "v" using {command down}
    delay 1 -- Without this, may restore clipboard before pasting.

    set the clipboard to _savedClipboard
end process

This is ugly and has some downsides: there are delays necessitated by the GUI scripting, and certain types of clipboard data are not preserved. But I can assign a single keyboard shortcut, which FastScripts won’t forget, and it works reliably.

Note: I originally wrote the script to use the clipboard instead of pbcopy and pbpaste. The latter are better because that way the text doesn’t end up in an AppleScript variable. Getting the text from AppleScript into stdin seems to require using either echo, which is subject to the shell’s command length limit, or writing to a temporary file.