Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View mourner's full-sized avatar
🔥
making stuff faster

Volodymyr Agafonkin mourner

🔥
making stuff faster
View GitHub Profile
@mourner
mourner / perf.log
Created March 9, 2018 20:42
Rollup GL JS perf log
Statistical profiling result from isolate-0x104801800-v8.log, (8048 ticks, 375 unaccounted, 0 excluded).
[Shared libraries]:
ticks total nonlib name
29 0.4% /usr/lib/system/libsystem_malloc.dylib
20 0.2% /usr/lib/system/libsystem_pthread.dylib
12 0.1% /usr/lib/system/libsystem_platform.dylib
8 0.1% /usr/lib/system/libsystem_c.dylib
3 0.0% /usr/lib/libc++abi.dylib
@mourner
mourner / contours.js
Created September 29, 2017 13:31
Quick example of generating GeoJSON contours from raster with d3
'use strict';
var contours = require('d3-contour').contours;
var PNG = require('pngjs').PNG;
var fs = require('fs');
var png = PNG.sync.read(fs.readFileSync('./rain.png'));
var data = [];
for (var i = 0; i < png.height; i++) {
@mourner
mourner / index.html
Last active December 2, 2019 02:29
Mapbox GL JS Puppeteer benchmark
<!doctype html>
<meta charset="utf-8">
<title>Benchmark</title>
<body></body>
<style>html, body, #map { height: 100%; margin: 0; } </style>
<div id="map"></div>
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.40.0/mapbox-gl.js'></script>
<!-- <script src="mapbox-gl.js"></script> -->
@mourner
mourner / simplify.wasm
Created September 7, 2017 10:54
WIP WebAssembly simplify
(module
(func $segDist (export "segDist")
(param $x0 f64) (param $y0 f64)
(param $x1 f64) (param $y1 f64)
(param $x2 f64) (param $y2 f64)
(result f64)
(local $x f64) (local $y f64)
(local $dx f64) (local $dy f64)
@mourner
mourner / index.js
Last active September 5, 2017 14:41
Fast GL JS expressions proof of concept
'use strict';
function genFn(ctx, body) {
let id = ctx.cache[body];
if (!id) {
id = ctx.id++;
ctx.cache[body] = id;
ctx.src += `
function e${id}() { ${body} }`;
}
@mourner
mourner / index.css
Last active May 31, 2023 07:00
Mapbox GL JS + SunCalc hack Friday
html, body {
margin: 0;
font-family: sans-serif;
}
#map {
position: absolute;
top: 45px;
bottom: 0;
@mourner
mourner / sunpos.js
Last active March 2, 2017 20:15
Minimal sun position calculating function
function getSunPosition(date, lat, lng) {
var r = Math.PI / 180, sin = Math.sin, cos = Math.cos, t = date / 315576e7 - 0.3,
m = r * (357.52911 + t * (35999.05029 - t * 1537e-7)), c = cos(r * (125.04 - 1934.136 * t)),
l = r * ((280.46646 + t * (36000.76983 + t * 3032e-7)) + (1.914602 - t * (4817e-6 - t * 14e-6)) *
sin(m) - (569e-5 + 478e-5 * c)) + (0.019993 - 101e-6 * t) * sin(2 * m) + 289e-6 * sin(3 * m),
e = r * (84381.448 - t * (46.815 - t * (59e-5 + 1813e-6 * t))) / 3600 + r * 256e-5 * c,
d = Math.asin(sin(e) * sin(l)),
h = r * (280.46061837 + 13184999.8983375 * t) + r * lng - Math.atan2(cos(e) * sin(l), cos(l)),
z = Math.atan2(sin(h), cos(h) * sin(r * lat) - (sin(d) / cos(d)) * cos(r * lat)),
a = Math.asin(sin(r * lat) * sin(d) + cos(r * lat) * cos(d) * cos(h));
@mourner
mourner / bench.js
Created January 17, 2017 18:02
Running a Mapbox GL JS benchmark in headless Electron
mapboxgl.accessToken = 'pk.eyJ1IjoibW91cm5lciIsImEiOiJWWnRiWG1VIn0.j6eccFHpE3Q04XPLI7JxbA';
console.log('Version: ' + mapboxgl.version);
const container = document.createElement('div');
container.style.width = '1200px';
container.style.height = '700px';
document.body.appendChild(container);
@mourner
mourner / arr.js
Created December 19, 2016 13:02
array vs typed array vs object for points
'use strict';
var v8 = require('v8');
var N = 1000000;
var values = [];
for (var i = 0; i < 2 * N; i++) values.push(Math.random());
var memStart = v8.getHeapStatistics().used_heap_size;
@mourner
mourner / approx.js
Created August 9, 2016 11:10
Mercator horner approximation
// not working
// based on https://github.com/Project-OSRM/osrm-backend/blob/master/include/util/web_mercator.hpp
'use strict';
function latY(lat) {
var sin = Math.sin(lat * Math.PI / 180);
return 0.5 - 0.25 * Math.log((1 + sin) / (1 - sin)) / Math.PI;
}