Getting categories in elementAPI performance issues and help required
I'm no expert on the elementAPI, and a better answer will most likely come, but the country and port fields are relations to different elements (i.e. categories)....so Craft by default uses lazy loading to load this data only when it is called on by default, as I understand it.  And that would probably be why the execution time jumps up.

What you really want to do, I think, is eager load this data as part of your initial query.

For resource on eager  loading, see:


https://craftcms.com/docs/templating/eager-loading-elements
https://straightupcraft.com/articles/examples-of-eager-loading-elements-in-twig-and-php


...so the question is, can you eager load in the element API?  I am not sure, but I'd suggest adding the with part to your criteria and trying it! I'm just guessing on the syntax here, but it looks like:

return [
    'elementType' =&gt; 'Entry',
    'criteria' =&gt; [
        'section' =&gt; 'directory',
        'relatedTo' =&gt; ['targetElement' =&gt; $category],
        'limit' =&gt; 1,
        'with' =&gt; ['country','port'],
    ],


...would be worth trying.  My gut feeling is this will work and will distinctly lower your execution time over the lazy loading way, but I'd love to get a report back!