What format are you trying to get your data into?
I can think of a few different ways to handle this depending on what you might want to do:
Element API
You don't mention what format you need but JSON is a popular format and the Element API is a first party solution in Craft.
Hidden Field
Another way to accomplish this would be to setup an Incognito field on your entry. Then, listen to the EVENT_BEFORE_SAVE_ELEMENT
event using a plugin to transform your data and save it to the format you need. This is similar to how you're doing it in Twig now, except just in a different "place" in the request.
This also has the advantage of doing the data transform once when the entry is saved (instead of every page load or messing around with {% cache %}
tags). Then you just grab it in Twig like any other field, similar to how you're doing it now.
Twig Filter
You mentioned this in your question. Since we don't have access to your Twig template, it's hard to know what you're trying to accomplish but I don't necessarily see a downside to doing it this way if your page performance is good. The only thing you might want to consider is adding {% cache %} tags around your output to give your server a break in that respect.
Page Injection
See Andrew's answer if you need to do things even "higher up" before the template layer.