Skip to content

Commit 1ecc875

Browse files
sofarnerzhul
authored andcommittedApr 29, 2017
Reorder TileLayer. (#5638)
Despite the split of TileSpec into TileDef and TileLayer, the TileLayer struct is still 66 bytes large, and doesn't fit in a single cacheline. I'm moving the color member to cacheline 2, in the hope that it is less used and the compiler loads all the hot members in a single cacheline instead. Only color sits now in cacheline 2, all the other members are in cacheline 1. Note: is_color is probably rarely set, most nodes will likely not use hardware coloring, but this may change in the future. Ideally, this class is shrunk to 64 bytes.
1 parent 19960e2 commit 1ecc875

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed
 

Diff for: ‎src/client/tile.h

+23-18
Original file line numberDiff line numberDiff line change
@@ -201,21 +201,21 @@ struct TileLayer
201201
{
202202
TileLayer():
203203
texture(NULL),
204+
normal_texture(NULL),
205+
flags_texture(NULL),
206+
shader_id(0),
204207
texture_id(0),
205-
color(),
208+
animation_frame_length_ms(0),
209+
animation_frame_count(1),
206210
material_type(TILE_MATERIAL_BASIC),
207211
material_flags(
208212
//0 // <- DEBUG, Use the one below
209213
MATERIAL_FLAG_BACKFACE_CULLING |
210214
MATERIAL_FLAG_TILEABLE_HORIZONTAL|
211215
MATERIAL_FLAG_TILEABLE_VERTICAL
212216
),
213-
shader_id(0),
214-
normal_texture(NULL),
215-
flags_texture(NULL),
216-
animation_frame_length_ms(0),
217-
animation_frame_count(1),
218-
has_color(false)
217+
has_color(false),
218+
color()
219219
{
220220
}
221221

@@ -286,27 +286,32 @@ struct TileLayer
286286
&& (material_flags & MATERIAL_FLAG_TILEABLE_VERTICAL);
287287
}
288288

289+
// Ordered for size, please do not reorder
290+
289291
video::ITexture *texture;
290-
u32 texture_id;
291-
/*!
292-
* The color of the tile, or if the tile does not own
293-
* a color then the color of the node owning this tile.
294-
*/
295-
video::SColor color;
296-
// Material parameters
297-
u8 material_type;
298-
u8 material_flags;
299-
u32 shader_id;
300292
video::ITexture *normal_texture;
301293
video::ITexture *flags_texture;
302294

303-
// Animation parameters
295+
u32 shader_id;
296+
297+
u32 texture_id;
298+
304299
u16 animation_frame_length_ms;
305300
u8 animation_frame_count;
301+
302+
u8 material_type;
303+
u8 material_flags;
304+
306305
//! If true, the tile has its own color.
307306
bool has_color;
308307

309308
std::vector<FrameSpec> frames;
309+
310+
/*!
311+
* The color of the tile, or if the tile does not own
312+
* a color then the color of the node owning this tile.
313+
*/
314+
video::SColor color;
310315
};
311316

312317
/*!

0 commit comments

Comments
 (0)
Please sign in to comment.