Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit ec90e6e

Browse files
committed
slab_allocator: remove SlabAllocator
Now that Buffer instantiation has improved, the SlabAllocator is an unnecessary layer of complexity preventing further performance optimizations. Currently there is a small performance loss with very small stream requests, but this will soon be addressed.
1 parent c1db1ec commit ec90e6e

File tree

6 files changed

+30
-227
lines changed

6 files changed

+30
-227
lines changed

node.gyp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@
108108
'src/smalloc.cc',
109109
'src/string_bytes.cc',
110110
'src/stream_wrap.cc',
111-
'src/slab_allocator.cc',
112111
'src/tcp_wrap.cc',
113112
'src/timer_wrap.cc',
114113
'src/tty_wrap.cc',
@@ -140,7 +139,6 @@
140139
'src/tcp_wrap.h',
141140
'src/udp_wrap.h',
142141
'src/req_wrap.h',
143-
'src/slab_allocator.h',
144142
'src/string_bytes.h',
145143
'src/stream_wrap.h',
146144
'src/tree.h',

src/slab_allocator.cc

Lines changed: 0 additions & 127 deletions
This file was deleted.

src/slab_allocator.h

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/stream_wrap.cc

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "node.h"
2323
#include "node_buffer.h"
2424
#include "handle_wrap.h"
25-
#include "slab_allocator.h"
2625
#include "stream_wrap.h"
2726
#include "pipe_wrap.h"
2827
#include "tcp_wrap.h"
@@ -33,8 +32,6 @@
3332
#include <stdlib.h> // abort()
3433
#include <limits.h> // INT_MAX
3534

36-
#define SLAB_SIZE (1024 * 1024)
37-
3835

3936
namespace node {
4037

@@ -49,6 +46,7 @@ using v8::Number;
4946
using v8::Object;
5047
using v8::Persistent;
5148
using v8::String;
49+
using v8::Uint32;
5250
using v8::Value;
5351

5452

@@ -58,23 +56,13 @@ static Persistent<String> write_queue_size_sym;
5856
static Persistent<String> onread_sym;
5957
static Persistent<String> oncomplete_sym;
6058
static Persistent<String> handle_sym;
61-
static SlabAllocator* slab_allocator;
6259
static bool initialized;
6360

6461

65-
static void DeleteSlabAllocator(void*) {
66-
delete slab_allocator;
67-
slab_allocator = NULL;
68-
}
69-
70-
7162
void StreamWrap::Initialize(Handle<Object> target) {
7263
if (initialized) return;
7364
initialized = true;
7465

75-
slab_allocator = new SlabAllocator(SLAB_SIZE);
76-
AtExit(DeleteSlabAllocator, NULL);
77-
7866
HandleScope scope(node_isolate);
7967

8068
HandleWrap::Initialize(target);
@@ -592,8 +580,7 @@ void StreamWrapCallbacks::AfterWrite(WriteWrap* w) {
592580

593581
uv_buf_t StreamWrapCallbacks::DoAlloc(uv_handle_t* handle,
594582
size_t suggested_size) {
595-
char* buf = slab_allocator->Allocate(wrap_->object_, suggested_size);
596-
return uv_buf_init(buf, suggested_size);
583+
return uv_buf_init(new char[suggested_size], suggested_size);
597584
}
598585

599586

@@ -604,26 +591,30 @@ void StreamWrapCallbacks::DoRead(uv_stream_t* handle,
604591
HandleScope scope(node_isolate);
605592

606593
if (nread < 0) {
607-
// If libuv reports an error or EOF it *may* give us a buffer back. In that
608-
// case, return the space to the slab.
609594
if (buf.base != NULL)
610-
slab_allocator->Shrink(Self(), buf.base, 0);
595+
delete[] buf.base;
611596

612597
SetErrno(uv_last_error(uv_default_loop()));
613598
MakeCallback(Self(), onread_sym, 0, NULL);
614599
return;
615600
}
616601

617-
Local<Object> slab = slab_allocator->Shrink(wrap_->object_, buf.base, nread);
602+
if (nread == 0) {
603+
if (buf.base != NULL)
604+
delete[] buf.base;
605+
return;
606+
}
607+
608+
// TODO(trevnorris): not kosher to use new/delete w/ realloc
609+
buf.base = static_cast<char*>(realloc(buf.base, nread));
618610

619-
if (nread == 0) return;
620611
assert(static_cast<size_t>(nread) <= buf.len);
621612

622613
int argc = 3;
623614
Local<Value> argv[4] = {
624-
slab,
625-
Integer::NewFromUnsigned(buf.base - Buffer::Data(slab), node_isolate),
626-
Integer::NewFromUnsigned(nread, node_isolate)
615+
Buffer::Use(buf.base, nread),
616+
Uint32::New(0, node_isolate),
617+
Uint32::New(nread, node_isolate)
627618
};
628619

629620
Local<Object> pending_obj;

src/stream_wrap.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ class StreamWrap : public HandleWrap {
135135
void UpdateWriteQueueSize();
136136

137137
private:
138-
static inline char* NewSlab(v8::Handle<v8::Object> global, v8::Handle<v8::Object> wrap_obj);
139-
140138
// Callbacks for libuv
141139
static void AfterWrite(uv_write_t* req, int status);
142140
static uv_buf_t OnAlloc(uv_handle_t* handle, size_t suggested_size);
@@ -151,7 +149,6 @@ class StreamWrap : public HandleWrap {
151149
template <enum encoding encoding>
152150
static v8::Handle<v8::Value> WriteStringImpl(const v8::Arguments& args);
153151

154-
size_t slab_offset_;
155152
uv_stream_t* stream_;
156153

157154
StreamWrapCallbacks default_callbacks_;

0 commit comments

Comments
 (0)