Skip to content

Remove in and readonly ref from Activity apis #29441

Closed
dotnet/corefx
#37395

Description

@benaadams

From "Shrink System.Diagnostics.Activity by 40 bytes" dotnet/corefx#37395

ActivitySpanId and ActivityTraceId can be shrunk to a single pointer size and made immutable meaning in and readonly ref are no longer required and become a disadvantage.

Also change the enums ActivityIdFormat and ActivityTraceFlags to be byte sized.

 public partial class Activity
 {
-    public ref readonly ActivitySpanId ParentSpanId { get { ... } }
+    public ActivitySpanId ParentSpanId { get { ... } }
-    public ref readonly ActivitySpanId SpanId { get { ... } }
+    public ActivitySpanId SpanId { get { ... } }
-    public ref readonly ActivityTraceId TraceId { get { ... } }
+    public ActivityTraceId TraceId { get { ... } }
-    public Activity SetParentId(in ActivityTraceId traceId, in ActivitySpanId spanId, ActivityTraceFlags activityTraceFlags = ActivityTraceFlags.None);
+    public Activity SetParentId(ActivityTraceId traceId, ActivitySpanId spanId, ActivityTraceFlags activityTraceFlags = ActivityTraceFlags.None);
 }

 public readonly partial struct ActivitySpanId : System.IEquatable<System.Diagnostics.ActivitySpanId>
 {
-    public static bool operator ==(in ActivitySpanId spanId1, in ActivitySpanId spandId2);
+    public static bool operator ==(ActivitySpanId spanId1, ActivitySpanId spandId2);
-    public static bool operator !=(in ActivitySpanId spanId1, in ActivitySpanId spandId2);
+    public static bool operator !=(ActivitySpanId spanId1, ActivitySpanId spandId2);
 }

 public readonly partial struct ActivityTraceId : System.IEquatable<System.Diagnostics.ActivityTraceId>
 {
-    public static bool operator ==(in ActivityTraceId traceId1, in ActivityTraceId traceId2);
+    public static bool operator ==(ActivityTraceId traceId1, SActivityTraceId traceId2);
-    public static bool operator !=(in ActivityTraceId traceId1, in ActivityTraceId traceId2);
+    public static bool operator !=(ActivityTraceId traceId1, ActivityTraceId traceId2);
 }

/cc @stephentoub @davidfowl

Activity

  1. bartonjs commented on May 3, 2019

    @bartonjs
    Member

    Also change the enums ActivityIdFormat and ActivityTraceFlags to be byte sized.

    I feel like they were originally proposed as byte-sized, but got expanded back to default/int in API review.

  2. stephentoub commented on May 3, 2019

    @stephentoub
    Member

    I feel like they were originally proposed as byte-sized, but got expanded back to default/int in API review.

    Right. There shouldn't be anything preventing them from being stored as a byte even if the enum itself has int as the underlying type... which Vance said is what was either already the case or was going to be the case, i.e. have our cake and eat it, too. If in the future we needed more than what byte could handle, we could change the implementation without needing to affect the API.

  3. benaadams commented on May 3, 2019

    @benaadams
    MemberAuthor

    K, removed that bit

  4. terrajobst commented on May 28, 2019

    @terrajobst
    Contributor

    Video

    @tommcdon / @noahfalk / @sywhang are you OK with this? This change looks good to us.

  5. tommcdon commented on May 28, 2019

    @tommcdon
    Member

    @terrajobst Looks good to me

  6. noahfalk commented on May 28, 2019

    @noahfalk
    Member

    LGTM

  7. transferred this issue fromdotnet/corefxon Feb 1, 2020
  8. added this to the 3.0 milestone on Feb 1, 2020
  9. ghost locked as resolved and limited conversation to collaborators on Dec 13, 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

    api-approvedarea-System.Diagnostics.Tracing

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions