Skip to content

How should history work? #5

@zyansheep

Description

@zyansheep

Issue on implementation details for readline history:

Up for debate

  • Should the history really be unchangeable?
  • Should this be hidden behind a feature flag?
  • The implementation (Implement a history #4) currently uses a Mutex to ensure thread-safety of appending new entries.
    Failing to acquire a lock (which should only be possible, if another thread panicked with the lock), will currently panic.
    Alternatives:
    • Pass lock errors through as a new type of error
    • Use a RwLock instead, currently not really useful as there aren't really any read-only accesses.
    • Remove the thread-safety and let the user handle mutable concurrent accesses to Readline
  • Should there be a way to get (read-only) access to the history from Readline?
  • Should this be separated into its own file? (Should be a general consideration in this library :) )
  • Should the constructor be changed into accepting struct/builder for the history size (and future additional parameters)?
  • The VecDeque used is currently created through default.
    Technically a capacity could be specified based on the max_size.
    This could consume unnecessarily large memory amounts when the max_size is high, but the history's actual length is low.

My Thoughts

Should the history really be unchangeable?

Probably... A history is a history because it happened in the past, and past in unchangeable.

Should this be hidden behind a feature flag?

Nahh

The implementation currently uses a Mutex to ensure thread-safety of appending new entries.
Failing to acquire a lock (which should only be possible, if another thread panicked with the lock), will currently panic.
Alternatives:
Pass lock errors through as a new type of error
Use a RwLock instead, currently not really useful as there aren't really any read-only accesses.
Remove the thread-safety and let the user handle mutable concurrent accesses to Readline
Should there be a way to get (read-only) access to the history from Readline?

My "perfect" history implementation would look something along the lines of :

  1. append-from-anywhere & read-from-anywhere like boxcar
  2. storage-agnostic system that allows for either in-memory history or sync-to-file history
    a. The downside sync-to-file is how its done, do we use Seek to look for newlines between history entries? Or do we manually serialize & deserialize the whole file whenever we want to sync? seeking & appending would be faster, but what happens if we want max history sizes? then the whole file needs to be rewritten which may require loading the entire thing into memory.

Should this be separated into its own file? (Should be a general consideration in this library :) )

Definitely, maybe even its own library to allow for other people to use it.

Should the constructor be changed into accepting struct/builder for the history size (and future additional parameters)?

That is a good idea, and is basically what rustyline does, which goes with the theme of trying to match their api.

Also to consider: do we want to have history searching (which would probably necessitate a BTree of some kind) or history deduplication?
This is how rustyline does it, no async tho: https://docs.rs/rustyline/6.3.0/src/rustyline/history.rs.html#25-30
I'm curious how ion does it, but I cannot grok their codebase...

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionDiscussion issues for feature designenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions