Skip to content

Instantly share code, notes, and snippets.

View funny-falcon's full-sized avatar

Sokolov Yura funny-falcon

View GitHub Profile
package main
import "fmt"
func A(x, y int) {
fmt.Println("The deferred A-call", x, y)
}
func B() int {
theAnswer := 42
@funny-falcon
funny-falcon / 00-test_hash_shift.rb
Last active March 15, 2024 04:20
Fix Ruby Hash#shift
require 'benchmark'
N = 50000
K = 10000
a = {}
K.times{|i| a[i] = nil}
class Hash
def custom_shift
require 'rational'
ONE = Rational(1)
def draw(arr)
print "N = #{arr.size}\n"
arr.each_with_index do |ar, i|
print "#{i}: (#{ar.size} items)\t#{ar.inspect}\n"
end
flat = arr.flatten
@funny-falcon
funny-falcon / atomic_linked_queue.rb
Last active December 16, 2015 03:29
Non blocking queue if we have attr_atomic
# rewrite of https://gist.github.com/jstorimer/5298581 if ruby has Class.attr_atomic
class AtomicLinkedQueue
class Node
attr_accessor :item, :successor
attr_atomic :successor
def initialize(item, successor)
@item = item
@successor = successor
@funny-falcon
funny-falcon / 00-description.md
Last active January 11, 2017 14:33
Performace patch for ruby-1.9.3-p327 detailed

This are parts of falcon patch for ruby-1.9.3-p327

  • 01-backport-speedup-require.diff - backport of Greg Price's patch for speedup require.

    For a long time my patch were famous cause of require speedup. ruby-core prefers slightly simpler patches from Greg Price, and I wish not to compete with ruby-core, so that I just backport accepted changes.

  • 02-st_opt.diff - speedup of Hash

This patch contains:

@funny-falcon
funny-falcon / changes.md
Last active March 23, 2024 05:53
Performace patch for ruby-1.9.3-p327

Changes:

  • this version includes backport of Greg Price's patch for speedup startup http://bugs.ruby-lang.org/issues/7158 .

    ruby-core prefers his way to do thing, so that I abandon cached-lp and sorted-lf patches of mine.

  • this version integrates 'array as queue' patch, which improves performance when push/shift pattern is heavily used on Array.

    This patch is accepted into trunk for Ruby 2.0 and last possible bug is found by Yui Naruse. It is used in production* for a couple of months without issues even with this bug.

@funny-falcon
funny-falcon / gist:4003797
Created November 2, 2012 19:30
IcedCoffeeScript examples
# Examples from http://andreypopp.com/posts/2012-10-30-callbacks-to-promises.html
# using IcedCoffeeScript http://maxtaco.github.com/coffee-script/ :
search = (engine, q, cb) ->
$.ajax(url: engine, success: cb)
await
search 'google', 'js', defer(googleSearched)
search 'bing', 'js', defer(bingSearched)
processResults(bingSearched, googleSearched)
await
@funny-falcon
funny-falcon / falcon.patch
Created September 14, 2012 12:07
Performance patch for ruby-1.9.3-head (applies to p194 as well)
diff --git a/array.c b/array.c
index 64647c3..618d9e3 100644
--- a/array.c
+++ b/array.c
@@ -255,15 +255,24 @@ rb_ary_modify(VALUE ary)
rb_ary_modify_check(ary);
if (ARY_SHARED_P(ary)) {
long len = RARRAY_LEN(ary);
+ VALUE shared = ARY_SHARED(ary);
if (len <= RARRAY_EMBED_LEN_MAX) {
@funny-falcon
funny-falcon / 00-description.md
Created September 14, 2012 12:05
Patches against ruby-1.9.3-head

This is falcon.patch splitted to be reviewed.

  • 01-cached-lp.diff - Cached expanded $LOAD_PATH - speedups startup
  • 02-sorted-lf.diff - Sorted $LOADED_FEATURES - tiny speedup startup
  • 03-st_opt.diff - Some improvements for hash creation
  • 04-sparse_array.diff - Performance improvement for methods/constants/instance variable offset tables
  • 05-ary-queue.diff - make array to be fully suitable as queue
  • 06-st_opt_sparse_array.diff - 03 + 04
  • 07-backport-gc.diff - backport of COW friendly GC