Optimal design and quantum limit for second harmonic generation in semiconductor heterostructures