Get page's highest-level ancestor

I’m aware this can be done with a recursive Twig macro if you’re after a certain property of the ancestor, eg.:

{% macro granddaddy_image(p) %},{% spaceless %}

  {% if p.parent.root %}
    {{ (p.media.images|first).url }}
  {% else %}
    {{ _self.granddaddy_image(p.parent) }}
  {% endif %}

{% endspaceless %},{% endmacro %}

<img src="{{ _self.granddaddy_image(page) }}" alt="img">

Is there a way of quickly retrieving the highest-level ancestor page as an object?

You can quickly reach the root like this:

{% set root = pages.root %}

however, that’s really a placeholder for the root node of user/pages/, within that are a bunch of top-level pages usually, and to get those you can do:

{% set root_pages = pages.root.children %}

However, to get the root page of the current page you are in, you must loop and climb back up the way you are already doing.

I’m not after the root, though - I’m after the node below that (relative to this page).

Then climbing back up, looping until the next parent is root is the way to go.