Change StringTable API a bit.#5286
Conversation
076bfcc to
d51802f
Compare
d51802f to
b57be6c
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5286 +/- ##
=======================================
Coverage 88.61% 88.62%
=======================================
Files 308 308
Lines 28125 28114 -11
Branches 7621 7618 -3
=======================================
- Hits 24923 24916 -7
+ Misses 2987 2984 -3
+ Partials 215 214 -1 ☔ View full report in Codecov by Sentry. |
79a6cff to
e8a5f06
Compare
|
I'm not opposed, but to avoid copies, I would have rather done a new static "constructor" taking a StringTable, not the backing array. From this static function it would be allowed to access the underlying array, but keeping the encapsulation of the array (and the synchronization with the map). This would also have skipped all the changes in the current use. |
Hmm, I'm not sure I understand your proposal. For example, in the upgraders, there are multiple upgraders that interact with the stringArray through a StringTable. Where would the second upgrader get the StringTable from the first upgrader? |
|
Ah yes, I see, for these cases the new factory function makes a lot of sense. Maybe I'd be happy enough with keeping the usage of the main constructor where its usage is not a problem. But again I'm not opposed to these changes so I'm also fine with keeping them like that. Now I guess I'm the reviewer :-) I'll look at it more closely soon |
julienw
left a comment
There was a problem hiding this comment.
As I wrote in the previous comment, I would mildly prefer to keep using the constructor in the cases it's not a problem (mostly when it's used without a parameter, as an empty table). But I'm also fine with your approach of replacing all of its uses.
Otherwise there's just one simple thing to improve IMO before landing it, see the comment below!
| thread.tid = i; | ||
| thread.name = name; | ||
| thread.stringTable = new StringTable(stringTable.serializeToArray()); | ||
| thread.stringTable = stringTable; |
There was a problem hiding this comment.
I wondered about that a bit: is it a problem that each thread have the same instance. But I guess it's fine.
There was a problem hiding this comment.
Yeah this is indeed a change in behavior, but I agree it should be fine. And soon (hopefully) we will have just one stringTable across all threads anyway.
| /** | ||
| * Exposes the underlying array. Do not mutate the contents. | ||
| */ | ||
| getBackingArray(): string[] { |
There was a problem hiding this comment.
return $ReadOnlyArray<string> so that Flow prevents mutating the items.
There was a problem hiding this comment.
I tried this but ran into an issue that I didn't know how to address: makeProfileSerializable calls getBackingArray() and stores the array in the SerializableThread's stringArray. So to make this work I would need to change the type of stringArray to $ReadOnlyArray<string>. But if I do that, then I break _unserializeProfile! Because it passes stringArray to StringTable.withBackingArray, which definitely cannot take a $ReadOnlyArray<string>.
There was a problem hiding this comment.
interesting, I guess this means we should have 2 types of SerializedThread, depending whether it's incoming or outgoing :-)
There was a problem hiding this comment.
Sorry, that was a bit on the flippant side. What I mean is: True, that would be a way to fix it! And it would express the intent well. But since I'm planning to get rid of the SerializedThread type anyway, I don't want to put too much effort into writing code that'll be deleted soon.
There was a problem hiding this comment.
Ah yeah, I should also have been explicit that I didn't want to do that now, it was more of a general thought.
This avoids copies of the underlying array. It also provides a new "constructor" (StringTable.withBackingArray) which avoids recreating the map when we need a StringTable for the same array in different places.
I would actually agree with you if all I had seen was this PR. But I'm going to leave it as I had it because it makes the stringArray commit in #5287 a bit simpler, I think. But I'm happy to revisit it in #5287. |
e8a5f06 to
ed9ff7f
Compare
Updates: [Nicolas Chevobbe] Adapt Keyboard shortcut dialog in High Contrast Mode. (#5245) [Nicolas Chevobbe] Fix sidebar-toggle in High Contrast Mode. (#5246) [Nicolas Chevobbe] Fix timeline selection overlay time / hover line in High Contrast Mode (#5247) [Zac Spitzer] fix broken link for processed profile format (#5267) [Greg Tatum] Update the memory allocation docs and add DHAT docs (#5270) [Markus Stange] Simplify some code related to thread CPU deltas (#5265) [Greg Tatum] Update dhat convertor to work better with valgrind (#5269) [Markus Stange] Rename UniqueStringArray to StringTable. (#5283) [Markus Stange] Use snapshot testing in the symbolicator CLI test. (#5284) [Markus Stange] Fix two confused upgraders which didn't expect to be run on the serialized format. (#5285) [Nicolas Chevobbe] Fix timelineSettingsHiddenTracks in High Contrast Mode. (#5250) [Julien Wajsberg] Fix some test and non-test warnings (#5294) [Nisarg Jhaveri] Support importing simpleperf trace files from Android Studio (#5212) [Sean Kim] Add HTTP response status code in the profiler network tab (#5297) [Markus Stange] Change StringTable API a bit. (#5286) [Markus Stange] Correctly declare imported simpleperf trace profiles to be of the current version. (#5312) [Markus Stange] Two small changes (#5313) [Nazım Can Altınova] Show sample tooltips on sample graph hover (#5298) Also thanks to our localizers: en-CA: chutten es-CL: ravmn es-CL: ravmn fr: Théo Chevalier ia: Melo46 ia: Melo46 sv-SE: Andreas Pettersson uk: Lobodzets zh-TW: Olvcpr423
This avoids copies of the underlying array.
It also provides a new "constructor" (StringTable.withBackingArray) which avoids recreating the map when we need a StringTable for the same array in different places.