As the leading distributed cyberinfrastructure for open scientific research in the United States, XSEDE supports several supercomputers across the country, as well as computational tools that are critical to the success of those researchers. In most cases, users are looking for a systematic way of selecting and configuring the available systems software and libraries for their applications so as to obtain optimal application performance. However, few scientific application developers have the time for an exhaustive search of all the possible configurations to determine the best one, and performing such a search empirically can consume a significant proportion of their allocation hours. We present here a framework, called the Performance Environment Autoconfiguration frameworK (PEAK), to help developers and users of scientific applications to select the optimal configuration for their application on a given platform and to update that configuration when changes in the underlying hardware and systems software occur. The choices to be made include the compiler with its settings of compiling options, the numerical libraries and settings of library parameters, and settings of other environment variables to take advantage of the NUMA systems. The framework has helped us choose the optimal configuration to get a significant speedup for some scientific applications executed on XSEDE platforms such as Kraken and Nautilus.