cherry-pick v3 of justarchi's archidroid optimizations