For me, like others above, research is split into two main types. Stuff I know I need to know at the beginning of the preparation for the book. And stuff I don't know I need to know until I've started writing.
The first type obviously happens as part of the development process, before the writing's even started, and centres around the characters and the main elements of the plot. The second type happens more organically as part of the writing process for me, where I get to a point where I can't progress without some particular piece of knowledge that I haven't got. This can be either an aspect of the main research that needs more detail, or it can be something unforseen.
The level and scope of the research depends on its importance to the plot and, more, the theme of whatever it is I'm writing. And what I research can also be divided into two areas. The first is the 'abstract', if you like, which feeds into the theme, the setting, the 'purpose' (to use Donna's lovely term) and the overall 'why' of the book. The second is the practical, which is the mechanics of how the various physical elements of the plot work and how the characters go about their daily activities.
With fantasy, you have a degree of lattitude in that you're dealing with a created world rather than depicting an existing reality. But the fictional reality that you're creating has to be internally consistent and 'workable'. So researching real-world paradigms - historical or current - is still vital (how would a lift work in the absence of electricity, steam or other 'modern' power source? How did large medieval cities tend to organise themselves? How were mercenaries paid? etc.).
With The Perfection Engine the main up-front research derived from the theme I wanted to write about - the concept of 'perfection' and wabi sabi, the Japanese aesthetic which centres on the acceptance of transience and imperfection - and the main protagonist - who would embody (literally) that theme and whose lived experience and voice it's critical that I portray accurately, truthfully and sensitively... for the success of the story and, more importantly, for moral and ethical reasons.
From the start, the intention was to write Membra as a 'standard' protagonist with no pre-judgment of what she could and could not do. The only rule is that for every action she takes, research or first hand experience has to provide either an existing 'real world' example of someone in a similar situation to her actually doing it, or, where that's not possible, whatever strategy she employs has to withstand a pretty rigorous feasibility check. She is allowed a very small degree of 'heroic exceptionalism' in borderline cases where the 'rule of cool' can be invoked without compromising believability.
The latter was, and still is, the biggest area of research, given that Membra's situation means that almost every single action that she takes, no matter how mundane, may require some level of explanation to the reader as to how she does it. Doing this, while still keeping the story about 'what Membra does' rather than 'how Membra does it', is a tricky balancing act.
I'm extremely fortunate to have a source of first-hand experience and knowledge to call on in this; someone who I've known for decades and who was both the instigator of and inspiration for Membra. She is invaluable for both practical advice and for insights into emotional and psychological aspects too. So sometimes the research is literally a quick email / phone call with a 'how would you...?' or an 'if you had to...?' question. Sometimes, though, it's a lot more time-consuming than that. But I've always rather enjoyed the research process... so it's not quite such an interruption as it might be.
How much of the research makes it into the actual text? As little as possible is my rule of thumb, and where it does have to appear I try and surreptitiously hide it in dialogue or specific verbs that convey what's happening without a blow-by-blow account. I don't always succeed though... and that's what editing (and honest feedback) is for! 😁