add graphite optimizations

credits to @metalspring