Skip to content

Commit b0c955d

Browse files
authored
[NFC] Remove excessive debug logging from binary reading (WebAssembly#6927)
We were doing a debug logging for every LEB byte. It turns out that the isDebugEnabled() calls are expensive when called so frequently: in a release+assertion build, even with debug disabled, these checks are the highest thing in the profile. This PR removes the checks, which makes binary reading 12% faster.
1 parent 34ee834 commit b0c955d

File tree

3 files changed

+8
-221
lines changed

3 files changed

+8
-221
lines changed

Diff for: src/passes/PostEmscripten.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <ir/table-utils.h>
2828
#include <pass.h>
2929
#include <shared-constants.h>
30+
#include <support/debug.h>
3031
#include <wasm-builder.h>
3132
#include <wasm-emscripten.h>
3233
#include <wasm.h>

Diff for: src/wasm-binary.h

+1-44
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,11 @@
2828
#include "ir/import-utils.h"
2929
#include "ir/module-utils.h"
3030
#include "parsing.h"
31-
#include "support/debug.h"
3231
#include "wasm-builder.h"
3332
#include "wasm-traversal.h"
3433
#include "wasm-validator.h"
3534
#include "wasm.h"
3635

37-
#define DEBUG_TYPE "binary"
38-
3936
namespace wasm {
4037

4138
enum {
@@ -158,18 +155,15 @@ class BufferWithRandomAccess : public std::vector<uint8_t> {
158155
BufferWithRandomAccess() = default;
159156

160157
BufferWithRandomAccess& operator<<(int8_t x) {
161-
BYN_TRACE("writeInt8: " << (int)(uint8_t)x << " (at " << size() << ")\n");
162158
push_back(x);
163159
return *this;
164160
}
165161
BufferWithRandomAccess& operator<<(int16_t x) {
166-
BYN_TRACE("writeInt16: " << x << " (at " << size() << ")\n");
167162
push_back(x & 0xff);
168163
push_back(x >> 8);
169164
return *this;
170165
}
171166
BufferWithRandomAccess& operator<<(int32_t x) {
172-
BYN_TRACE("writeInt32: " << x << " (at " << size() << ")\n");
173167
push_back(x & 0xff);
174168
x >>= 8;
175169
push_back(x & 0xff);
@@ -180,7 +174,6 @@ class BufferWithRandomAccess : public std::vector<uint8_t> {
180174
return *this;
181175
}
182176
BufferWithRandomAccess& operator<<(int64_t x) {
183-
BYN_TRACE("writeInt64: " << x << " (at " << size() << ")\n");
184177
push_back(x & 0xff);
185178
x >>= 8;
186179
push_back(x & 0xff);
@@ -199,47 +192,19 @@ class BufferWithRandomAccess : public std::vector<uint8_t> {
199192
return *this;
200193
}
201194
BufferWithRandomAccess& operator<<(U32LEB x) {
202-
[[maybe_unused]] size_t before = -1;
203-
BYN_DEBUG(before = size(); std::cerr << "writeU32LEB: " << x.value
204-
<< " (at " << before << ")"
205-
<< std::endl;);
206195
x.write(this);
207-
BYN_DEBUG(for (size_t i = before; i < size(); i++) {
208-
std::cerr << " " << (int)at(i) << " (at " << i << ")\n";
209-
});
210196
return *this;
211197
}
212198
BufferWithRandomAccess& operator<<(U64LEB x) {
213-
[[maybe_unused]] size_t before = -1;
214-
BYN_DEBUG(before = size(); std::cerr << "writeU64LEB: " << x.value
215-
<< " (at " << before << ")"
216-
<< std::endl;);
217199
x.write(this);
218-
BYN_DEBUG(for (size_t i = before; i < size(); i++) {
219-
std::cerr << " " << (int)at(i) << " (at " << i << ")\n";
220-
});
221200
return *this;
222201
}
223202
BufferWithRandomAccess& operator<<(S32LEB x) {
224-
[[maybe_unused]] size_t before = -1;
225-
BYN_DEBUG(before = size(); std::cerr << "writeS32LEB: " << x.value
226-
<< " (at " << before << ")"
227-
<< std::endl;);
228203
x.write(this);
229-
BYN_DEBUG(for (size_t i = before; i < size(); i++) {
230-
std::cerr << " " << (int)at(i) << " (at " << i << ")\n";
231-
});
232204
return *this;
233205
}
234206
BufferWithRandomAccess& operator<<(S64LEB x) {
235-
[[maybe_unused]] size_t before = -1;
236-
BYN_DEBUG(before = size(); std::cerr << "writeS64LEB: " << x.value
237-
<< " (at " << before << ")"
238-
<< std::endl;);
239207
x.write(this);
240-
BYN_DEBUG(for (size_t i = before; i < size(); i++) {
241-
std::cerr << " " << (int)at(i) << " (at " << i << ")\n";
242-
});
243208
return *this;
244209
}
245210

@@ -249,21 +214,17 @@ class BufferWithRandomAccess : public std::vector<uint8_t> {
249214
BufferWithRandomAccess& operator<<(uint64_t x) { return *this << (int64_t)x; }
250215

251216
BufferWithRandomAccess& operator<<(float x) {
252-
BYN_TRACE("writeFloat32: " << x << " (at " << size() << ")\n");
253217
return *this << Literal(x).reinterpreti32();
254218
}
255219
BufferWithRandomAccess& operator<<(double x) {
256-
BYN_TRACE("writeFloat64: " << x << " (at " << size() << ")\n");
257220
return *this << Literal(x).reinterpreti64();
258221
}
259222

260223
void writeAt(size_t i, uint16_t x) {
261-
BYN_TRACE("backpatchInt16: " << x << " (at " << i << ")\n");
262224
(*this)[i] = x & 0xff;
263225
(*this)[i + 1] = x >> 8;
264226
}
265227
void writeAt(size_t i, uint32_t x) {
266-
BYN_TRACE("backpatchInt32: " << x << " (at " << i << ")\n");
267228
(*this)[i] = x & 0xff;
268229
x >>= 8;
269230
(*this)[i + 1] = x & 0xff;
@@ -276,16 +237,12 @@ class BufferWithRandomAccess : public std::vector<uint8_t> {
276237
// writes out an LEB to an arbitrary location. this writes the LEB as a full
277238
// 5 bytes, the fixed amount that can easily be set aside ahead of time
278239
void writeAtFullFixedSize(size_t i, U32LEB x) {
279-
BYN_TRACE("backpatchU32LEB: " << x.value << " (at " << i << ")\n");
280240
// fill all 5 bytes, we have to do this when backpatching
281241
x.writeAt(this, i, MaxLEB32Bytes);
282242
}
283243
// writes out an LEB of normal size
284244
// returns how many bytes were written
285-
size_t writeAt(size_t i, U32LEB x) {
286-
BYN_TRACE("writeAtU32LEB: " << x.value << " (at " << i << ")\n");
287-
return x.writeAt(this, i);
288-
}
245+
size_t writeAt(size_t i, U32LEB x) { return x.writeAt(this, i); }
289246

290247
template<typename T> void writeTo(T& o) {
291248
for (auto c : *this) {

0 commit comments

Comments
 (0)