Skip to content

Make Entity serializable #323

Description

@WhiteBlackGoose

And make FieldCache non-serializable

Activity

  1. added this to the 1.2.1 milestone on Feb 25, 2021
  2. removed this from the 1.3 milestone on Mar 14, 2021
  3. WhiteBlackGoose commented on Apr 5, 2021

    @WhiteBlackGoose
    MemberAuthor

    @Happypig375 the fact that Entity will be serializable doesn't imply by default what exact framework or technique we will use for it. Probably, it will be similar to ToString and return a base64 format. And a MathS.Deserialize will create an Entity back from a serialized one.

    That's my thoughts, but there should be serialization, so that you could save your formulas, or send somewhere, etc. Remember, that we don't guarantee a.ToString().ToEntity() be parsable and equal to a.

  4. Happypig375 commented on Apr 6, 2021

    @Happypig375
    Member

    So why not an existing and widespread format like JSON, XML, YML, etc.?

  5. Happypig375 commented on Apr 6, 2021

    @Happypig375
    Member

    Or not just Parse/ToString?

  6. WhiteBlackGoose commented on Apr 6, 2021

    @WhiteBlackGoose
    MemberAuthor

    Maybe we will take JSON, I don't know. I just thought that maybe we want a compressed and fast format

  7. Happypig375 commented on Apr 6, 2021

    @Happypig375
    Member

    Just Stringize/Parse should be compressed enough, right? I don't know about fast though, but shouldn't be much slower.

  8. WhiteBlackGoose commented on Apr 6, 2021

    @WhiteBlackGoose
    MemberAuthor

    Like I said, a.ToString().ToEntity() != a. Say, is 1 + 2 + 3 same as (1 + 2) + 3 or 1 + (2 + 3)? For this one we have ExplicitOutput setting, but in general, it might be not parsable back. Also, we need to check how slower it is to parse than to convert from a binary expression.

  9. modified the milestone: Future on May 13, 2021
  10. Rafael-SOWNet commented on Aug 23, 2026

    @Rafael-SOWNet
    Member

    #1031 does the serialization half, as JSON through System.Text.Json, with the printed form as the
    format — so Parse/ToString, which is what @Happypig375 asked twice, wrapped so that an Entity
    works as a member of a serializable type without the caller doing anything.

    Measured before changing anything, on v2.3.0: JsonSerializer.Serialize(entity) threw for every
    entity, (Entity)3 included — Nodes is a node's enumeration of itself, so the reflecting converter
    walked it until it reported an object cycle. DataContractSerializer refused the types and
    typeof(Entity).IsSerializable was false. So there was no way to serialize an expression at all,
    which is the concrete thing this issue names.

    On the "compressed and fast" thought: reading a 43-node textbook expression costs about 430 us and
    0.8 MB through the parser, against 6.5 us and 25 kB to build the same tree from constructors. That
    gap is real, and the PR argues it is a case for a faster parser rather than for a second
    representation that only serialization uses and that can drift from the printed one.

    @WhiteBlackGoose your objection has narrowed rather than gone. StringizeRoundTripTest and
    EveryNodeSurvivesEveryPipelineTest do enforce a.Stringize() parsing back to a for every node
    type now — but your own example still stands: 1 + (2 + 3) prints as 1 + 2 + 3 and reads back as
    (1 + 2) + 3, because a right operand of equal priority is not bracketed. Shape and not value for
    every associative operator; for implies it is value, and that is #1032. Codomain is never
    printed at all, which is #1022.

    Two things before this closes, neither of which I have touched:

    • the second half of this issue, "and make FieldCache non-serializable", names a type that no
      longer exists — the memoisation is LazyPropertyA<T> fields now, and nothing reads a field of a
      node any more because the expression is written as text. The reason for it is gone rather than
      answered, and that is a maintainer's call.
    • netstandard2.0 is not covered: it has no System.Text.Json in the box and the csproj takes no
      package reference for it.
  11. added this to the Future milestone on Sep 18, 2026
  12. modified the milestones: Future, 3.0 on Sep 18, 2026
  13. Happypig375 commented on Sep 18, 2026

    @Happypig375
    Member

    Let's drop netstandard2.0 for v3 and have .NET 10 as the baseline for v3 - JsonSerializer support will then be implicitly available. Note this down for #1019

    Let's attempt to make Stringize and parsing as fast as possible with as little memory as possible before deciding that we need a whole new format

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

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions