Skip to content

Performance optimisation: Specialised AbstactDict for VarNames? #1116

@mhauru

Description

@mhauru

We have a lot of structures where we use Dict{T<:VarName} or sometimes OrderedDict{T<:VarName}. Since these get used in the deep internals of all VarInfo types (except SVI with NamedTuples, but that one has its own problems), and since Dicts are quite heavy and slow, I've been wondering if we could optimise this.

I'm imagining writing our own AbstractDict type that is hardcoded to have VarNames as keys. I'm not sure how to best do it, but one idea I have is that if we define an ordering on VarNames, which should be relatively natural to do (@penelopeysm tells me that she may already have code for this), we could probably exploit that by doing binary searches on a balanced binary tree or something, instead of hashes and hashmaps. Even if we stick with a hashmap, other optimisations might be available, e.g. a custom hash function. Maybe we could also use a VarNamedTuple (#900) for this.

If this gets implemented it should go in AbstractPPL, but opening the issue here since this is where it would get used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions