Skip to content

Commit 568e7e1

Browse files
authored
[ESI][Runtime] Translate message performance enhancements (#9330)
This PR optimizes the performance of window type message translation in the ESI Runtime by precomputing translation metadata at connection time. Instead of computing field offsets and performing multiple small memory copies for each message, the translation information is now computed once and stored as an optimized array of copy operations that are sorted and merged to minimize runtime overhead.
1 parent 024a0e8 commit 568e7e1

File tree

2 files changed

+172
-168
lines changed

2 files changed

+172
-168
lines changed

lib/Dialect/ESI/runtime/cpp/include/esi/Ports.h

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,41 @@ class ChannelPort {
113113

114114
protected:
115115
const Type *type;
116-
const WindowType *translationType;
116+
117+
/// Instructions for translating windowed types. Precomputes and optimizes a
118+
/// list of copy operations.
119+
struct TranslationInfo {
120+
TranslationInfo(const WindowType *windowType) : windowType(windowType) {}
121+
122+
/// Precompute and optimize the copy operations for translating frames.
123+
void precomputeFrameInfo();
124+
125+
/// The window type being translated.
126+
const WindowType *windowType;
127+
128+
/// A copy operation for translating between frame data and the translation.
129+
/// Run this during the translation.
130+
struct CopyOp {
131+
/// Offset in the incoming/outgoing frame data.
132+
size_t frameOffset;
133+
/// Offset in the translation buffer.
134+
size_t bufferOffset;
135+
/// Number of bytes to copy.
136+
size_t size;
137+
};
138+
/// Information about each frame in the windowed type.
139+
struct FrameInfo {
140+
/// The total size of a frame in bytes.
141+
size_t expectedSize;
142+
/// Precomputed copy operations for translating this frame.
143+
std::vector<CopyOp> copyOps;
144+
};
145+
/// Precomputed information about each frame.
146+
std::vector<FrameInfo> frames;
147+
/// Size of the 'into' type in bytes.
148+
size_t intoTypeBytes = 0;
149+
};
150+
std::unique_ptr<TranslationInfo> translationInfo;
117151

118152
/// Method called by poll() to actually poll the channel if the channel is
119153
/// connected.
@@ -130,7 +164,9 @@ class WriteChannelPort : public ChannelPort {
130164
using ChannelPort::ChannelPort;
131165

132166
virtual void connect(const ConnectOptions &options = {}) override {
133-
translateMessages = options.translateMessage && translationType;
167+
translateMessages = options.translateMessage && translationInfo;
168+
if (translateMessages)
169+
translationInfo->precomputeFrameInfo();
134170
connectImpl(options);
135171
connected = true;
136172
}

0 commit comments

Comments
 (0)