lib: performance improvements