Write an optimized algorithm to find all prime numbers up to a given limit, and discuss its time and space complexity.