Skip to content

Unnecessary use of Once? #253

Closed
Closed

Description

@Kriskras99

To allow configuring the memory limit and human readable (de)serialisation we currently use std::sync::Once:

static MAX_ALLOCATION_BYTES_ONCE: Once = Once::new();

static SERDE_HUMAN_READABLE_ONCE: Once = Once::new();

Once is a low-level primitive and although correct not really the right tool for the job (anymore). Something like OnceLock::get_or_init provides the same functionality as Once + AtomicUsize/Bool in a much nicer API.

But I also think only allowing it to be set once is not necessarily the right thing either. I can imagine a program that might want to increase its limit if it encounters files that are too large iff the computer it's running on has spare resources.

Activity

  1. martin-g commented on Aug 10, 2025

    @martin-g
    Member

    Before it was using lazy_static. I've replaced it with Once to get rid of the extra dependency. OnceLock was not stable at the time but we can use it now!

    I am not sure about the idea of making it editable at runtime. It will add extra complexity and no one really asked for it yet.

  2. Kriskras99 commented on Aug 10, 2025

    @Kriskras99
    ContributorAuthor

    I'll open a PR for this somewhere next week.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions