Skip to content

Instantly share code, notes, and snippets.

View atdt's full-sized avatar
💭
in rainbows

Ori Livneh atdt

💭
in rainbows
  • Google
  • New York City
View GitHub Profile
<?php
// $ /usr/bin/hhvm -vEval.Jit=1 --count 10 outer.php
// mapValues: 148.63 mapValuesUse: 76.83
// mapValues: 74.01 mapValuesUse: 55.72
// mapValues: 67.03 mapValuesUse: 55.68
// mapValues: 67.34 mapValuesUse: 55.75
// mapValues: 67.08 mapValuesUse: 55.75
// mapValues: 67.15 mapValuesUse: 55.80
// mapValues: 67.14 mapValuesUse: 55.83
@atdt
atdt / slicer.py
Created September 28, 2015 17:53
Slice command line argument
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument(
'--slice',
default='-2:',
type=slicer,
)
args = arg_parser.parse_args()
def slicer(spec):
@atdt
atdt / ago.py
Created September 26, 2015 06:23
def time_ago(s):
units = ((86400, 'day'), (3600, 'hour'), (60, 'minute'), (1, 'second'))
ago = next('%s %s' % (s // len, unit) for len, unit in units if s > len)
return '%s ago' % (ago if ago.startswith('1 ') else ago + 's')
@atdt
atdt / story.md
Last active September 24, 2015 21:20
Detective story

Looking at performance data for load.php requests, I notice that we spend quite a lot of time in SitesModuleWorker::getSitesHash(). So I would like to know what that method does.

I grep for it, and find that it calls SitesModuleWorker::getSites(). SitesModuleWorker::getSites(), in turn, calls SiteStore::getSites().

But SiteStore is an interface, and I don't know which concrete implementation SitesModuleWorker is using, because the implementation is specified via a parameter to SitesModuleWorker::__construct(). So I need to look and see where SitesModuleWorker is instantiated.

That takes me to lib/includes/modules/SitesModule.php:29, where I see that it is SiteSQLStore::newInstance(). OK.

But where is SiteSQLStore? Oh, I see that it's in Core. OK, let's pull it up and see what its SiteSQLStore::getSites() method does.

@atdt
atdt / what-forces-layout.md
Last active September 19, 2015 17:30 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
<?php
/*
Quick perf test for DeferredUpdates
Results from running this on mw1017:
$ /usr/bin/hhvm -vEval.Jit=1 --count 10 x.php
Executed 1000 DeferredUpdates in 81.25ms
Executed 1000 DeferredUpdates in 1.88ms
Executed 1000 DeferredUpdates in 1.96ms
from __future__ import division
import collections
import re
import os
import os.path
import glob
import argparse
ignore_prefixes = (
'/srv',
@atdt
atdt / bench.php
Created September 7, 2015 19:23
Benchmarking script for I2f67a2b7
<?php
// Benchmarking script for https://gerrit.wikimedia.org/r/#/c/236401/
// Run with: /usr/bin/hhvm -vEval.Jit=1 --count 40 bench.php
// '--keys=NNN' specifies number of keys to read. Defaults to 200.
require_once __DIR__ . "/src/Util.php";
require_once __DIR__ . "/src/Exception.php";
require_once __DIR__ . "/src/Reader.php";
require_once __DIR__ . "/src/Reader/PHP.php";
#!/usr/bin/env bash
while IFS= read -r gitreview; do
if grep -q wikimedia "$gitreview" ; then
cd "$(dirname "$gitreview")"
mr register
fi
done < <(find ~/git -name .gitreview)
@atdt
atdt / lcz
Last active August 30, 2015 05:45
lcz -- estimate line-count of gzip file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
lcz -- estimate line-count of gzip file
Intended for log files with regular line lengths and content.
Usage: lcz FILE
"""
import gzip