Debug and optimize a service at Duolingo that processes user input and returns matching vocabulary suggestions. Implement prefix matching over vocabulary entries, rank matches by descending frequency, and break ties lexicographically. The function receives vocabulary, a list of objects with word and frequency, a query string, and a result limit, and returns up to that many original words.
def vocabulary_suggestions(vocabulary, query, limit):