nodejs / llparse

Generating parsers in LLVM IR
http://llparse.org
Other
584 stars 30 forks source link

${options.prefix}_s struct size #35

Closed fanatid closed 4 years ago

fanatid commented 4 years ago

If int32_t index; from https://github.com/nodejs/llparse/blob/v6.2.1/src/compiler/header-builder.ts#L31 will be moved to next int32_t https://github.com/nodejs/llparse/blob/v6.2.1/src/compiler/header-builder.ts#L40 this will save 8 bytes on x64. Does it makes sense to change definition order?

llhttp (96 => 88):

#include <inttypes.h>
#include <stdio.h>

struct llhttp__internal_s {
  int32_t _index;
  void* _span_pos0;
  void* _span_cb0;
  int32_t error;
  const char* reason;
  const char* error_pos;
  void* data;
  void* _current;
  uint64_t content_length;
  uint8_t type;
  uint8_t method;
  uint8_t http_major;
  uint8_t http_minor;
  uint8_t header_state;
  uint16_t flags;
  uint8_t upgrade;
  uint16_t status_code;
  uint8_t finish;
  void* settings;
};

struct llhttp__internal_s2 {
  void* _span_pos0;
  void* _span_cb0;
  int32_t _index;
  int32_t error;
  const char* reason;
  const char* error_pos;
  void* data;
  void* _current;
  uint64_t content_length;
  uint8_t type;
  uint8_t method;
  uint8_t http_major;
  uint8_t http_minor;
  uint8_t header_state;
  uint16_t flags;
  uint8_t upgrade;
  uint16_t status_code;
  uint8_t finish;
  void* settings;
};

int main() {
  printf("%ld %ld\n", sizeof(struct llhttp__internal_s), sizeof(struct llhttp__internal_s2));
  return 0;
}
fanatid commented 4 years ago

Implemented in #36 do not see purpose hold it open.