Skip to content

[File format] Only write out ragged columns if data_length > 0 #538

Closed as not planned

Description

@jeromekelleher

Since we've added metadata to the edges table, we have a significant extra storage burden. In the (very) common case in which we store no metadata at all for edges, we will need to store a metadata_offset column which consists entirely of zeros. Since our load logic can handle this pair of metadata/metadata_offset pair as being optional, we should clearly not store this column pair when no metadata is stored. Similarly for the migration metadata. Since these are new columns, there is no problem with backwards/forwards compatability.

The question then is whether we should generalise this logic for all ragged column pairs. If nothing is being stored in the column, then it seems like a good idea to not store the offset column. The semantics are clear. The only problem then is backward compatability --- since older versions of the code expect all these fields to be specified, we will need to bump the file major version number.

I think it's worth doing this, because there are a some large tree sequence files out there that have no metadata associated with nodes, sites, mutations etc, and it's a waste of space storing large arrays of zeros. Note that it's only older versions of the code that won't be able to read new files: we should change tskit so that it can still read version 12 files (the current major version) as well as version 13. So, the only inconvenience to users is that they'll need to update their version of tskit if they want to read version 13 files. Thus, no file upgrades will be needed (although we can provide one, as it'll make some files a bit smaller).

(If we agree with this file version bump, then I think we should get some other semantic tweaks in, such as if the data column is present and its length is equal to num_rows, then the offset columns is assumed to be range(0, num_rows + 1). This will remove the need to store the offset column in the (very) common case where ancestral_state and derived_state are all one character long. We can easily detect this at write time, and drop the offset column appropriately. We should follow this up in another issue though, if we agree with the basic direction of travel.)

See also #537

Activity

  1. added
    enhancement
    on Apr 15, 2020
  2. petrelharp commented on Apr 15, 2020

    @petrelharp
    Contributor

    Sounds good to me!

    if the data column is present and its length is equal to num_rows, then the offset columns is assumed to be range(0, num_rows + 1)

    This seems like a bigger can of worms, since lots of code uses the offset columns, including in python. I suppose that we could have the python layer return the appropriate thing if the offset column is asked for and it's not there, and deal with changes to the C?

  3. jeromekelleher commented on Apr 15, 2020

    @jeromekelleher
    MemberAuthor

    This seems like a bigger can of worms, since lots of code uses the offset columns, including in python. I suppose that we could have the python layer return the appropriate thing if the offset column is asked for and it's not there, and deal with changes to the C?

    Sorry, I wasn't clear here. The tables API always has valid memory and columns defined as part of its contract, it's just the file format we're talking about here. It's much too complicated and awkward otherwise.

  4. petrelharp commented on Apr 15, 2020

    @petrelharp
    Contributor

    Sorry, I wasn't clear here.

    Well, it does say "[File Format]" up at the top... =)

    In that case, I wonder if it's worth the trouble, because memory is often more constraining than disk space? I'm not opposed, though, and having smaller files for lots of simulations would be nice.

  5. jeromekelleher commented on Apr 15, 2020

    @jeromekelleher
    MemberAuthor

    In that case, I wonder if it's worth the trouble, because memory is often more constraining than disk space? I'm not opposed, though, and having smaller files for lots of simulations would be nice.

    Some people store lots of simulations, you'd be surprised. On the other hand, I'd be extremely surprised if many people have hit practical memory limitations with loading tree sequences. You can still fit a very big tree sequence in a gig of RAM, which is basically the smallest unit of RAM you would ever allocate to a single core.

  6. petrelharp commented on Apr 15, 2020

    @petrelharp
    Contributor

    I'd be extremely surprised if many people have hit practical memory limitations with loading tree sequences

    I'm pretty sure it's a substantial factor in SLiM simulations: these are extra-big, because we're storing everyone across a bunch of generations (between simplifications), and because slim is single-core, so reducing memory footprint would let us use more cores per machine. But this is orthogonal to this issue...

  7. jeromekelleher commented on Apr 15, 2020

    @jeromekelleher
    MemberAuthor

    Your right, I keep forgetting that SLiM builds big tables in memory. Hmm, that does put a different spin on it, and perhaps some flags at create time (NO_METADATA) or something would help. It'll complicate the code a bit, but save a fair bit of memory.

    Anyway, orthogonal, as you say.

  8. added this to the C API 0.99.3 milestone on May 7, 2020
  9. jeromekelleher commented on Jul 6, 2020

    @jeromekelleher
    MemberAuthor

    Pushing this out to 0.99.4 because 0.99.3 now only involves a minor file format version bump.

  10. added
    C API
    on Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C APIenhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions