Brainiac is often used for this. Although it originally was the name of a comic supervillain, when used to describe a person, it doesn't imply any evil or villainous behavior, but just a very intelligent or knowledgeable person.
It usually indicates either grudging respect or affectionate envy for someone who is very smart or knowledgeable. It's not really derogatory, though like any positive term term it can be used sarcastically to mean the opposite.
"Gerald is such a brainiac, he got a perfect score on his calculus test and I just barely got a C."
There's even a line of snack products which use Brainiac in their trademark for snacks which supposedly improve brain development in children. Regardless of whether they actually work, the fact that the word is used to appeal to parents who want smart children shows that it's not derogatory.
Genius is also sometimes used for this in relation to a specific topic, as in "He's a genius at baseball stats."