def _fastmerge(a, b):
    """
    Fast recusrive merge of dicts and list.

    Fast merge avoids copying dicts and list but also avoids mutating objects.
    It operates by rebuilding nested datasets from top to bottom if necessary.
    """
    if isinstance(a, dict) and isinstance(b, dict):
        if not b:  # If B is empty we can return A
            return a

        # Prepare new dict with everything in A that is not in B and therefore
        # does not need to be rebuild.
        data = {k: v for k, v in a.items() if k not in b}

        for k, v in b.items():
            # Merge everthing in A and B but only copy things from B that are
            # not in A.
            data[k] = _fastmerge(a[k], v) if k in a else v

        return data

    if isinstance(a, list) and isinstance(b, list):
        # Lists are just appended
        return [*a, *b]

    return b