r/Compilers • • 16d ago

Why is my C++ dynamic runtime backend slower than CPython?

Hi everyone,

I'm 15 and building my own dynamically-typed programming language. The repository below is the C++ runtime/backend I wrote to handle variables, memory, and cross-type operations:

Repo: https://github.com/mxrfp/Dynamic-Type-System-in-C-

To avoid dynamic_cast and heap fragmentation, I built it around:

Double Dispatch via virtual functions to resolve operations like Int + Float or String Int.

std::pmr::unsynchronized_pool_resource inside an RAII wrapper (`Type`) to manage object lifetimes.

Since it's written in C++ with a custom memory pool, I expected it to be at least slightly faster than Python on basic benchmarks instead, it turns out to be slower than CPython.

The code is still very premature, so I'd really appreciate it if someone with more experience could take a look and help me understand where the main performance bottlenecks are.

Thanks in advance!

10 Upvotes

12 comments sorted by

7

u/AdearienRDDT 16d ago

Hey, It's impressive and i commend you for going into such deep topics, and for caring about performance!

My shallow advice would be to use tools like perf and make your program run for an extended period of time, perf is a profiler and with it you will diagnose what makes your program slow, where does your program get stuck for the longest time.

Google' Benchmarking library comes to mind aswell if you wanna give it a try.

Good luck!

5

u/WittyStick 16d ago edited 16d ago

Performance issues usually come down to the machine. The primary bottleneck is still main memory access. Cache somewhat mitigates this - but only if used efficiently. Branch predictors are also essential to performance - as a correctly predicted branch has a tiny cost, but a branch misprediction can be expensive. Avoiding branch mispredictions is difficult for dynamically typed languages - but JIT-compilation can be used to reduce them.

To write high-performance dynamically typed code, you should have a good understanding of how the machine works, and how code is compiled to the ABI on your target platform.

In C++, each virtual function call must be looked up in a vtable, and an indirect branch instruction will decide where to jump. Indirect jumps rely on a branch target predictor to work well - but dynamic code doesn't really have a particular pattern which informs the predictor which virtual method will be called - so it will end up mispredicting a large number of branches.

The other issue you have is passing around pointers to Object everywhere. Every dereference has a multi-cycle cost even if the value is in L1 cache - but if it isn't - and a main memory fetch is required, it costs ~100 cycles. Your CPU will be sat idle waiting for values to be read when it could be performing other instructions.

Two main approaches you want to optimize a dynamically typed language:

  • Avoid dereferencing as much as is possible.
  • Avoid branching as much as is possible.

The first thing to look at is your representation of values. Every value lives in memory - a binary operation requires 2 loads (~5 cycles each), one allocation (hundreds of cycles), one store (~5 cycles) - plus the desired operation (which is typically ~1-3 cycles), plus two indirect branches. The biggest cost is the allocation - the second biggest cost is branching - the third biggest cost is load/store.

Suppose we have an operation like: 1 + 2 * 3. We first compute 2 * 3 = 6, and store this intermediate result in some allocated memory, then we load it again to add 1 to it. The intermediate result 6 is then just sat somewhere in memory waiting for garbage collection, even though we never needed the value 6 - we wanted the value 7.

The value 6 is a value that we shouldn't need to store. It only needs to exist in a machine register temporarily, until we add 1 to it. We can completely avoid allocating space for this value. What we want is for integers and floats to be value types, and to only need a pointer for larger values like strings, which are reference types.

The way we do this is so called "type tagging". There are lots of different techniques for it - many covered in Gudeman's 1993 paper Representing Type Information in Dynamically Typed Languages - though this is a little dated - it's still worthwhile reading to understand the techniques.

The basic idea is we want to represent a value and its type in our dynamically typed language in one or two machine registers. Where we can't fit it into the one or two registers - we hold a pointer in the machine register to a value of arbitrary size.

So for integers and floats for example - these fit into a machine register - we shouldn't need to allocate memory for them except to load and store eventual results. Strings on the other hand, require allocation because they're seldom <8-bytes (size of a register on a 64-bit machine).


A technique that works well on 64-bit SYSV platforms (Linux, Mac, BSD etc), is to use a 2-machine word struct, where one contains a type tag and the other a payload which depends on the tag.

typedef enum { 
    TAG_NONE, 
    TAG_BOOL, 
    TAG_INT,
    TAG_FLOAT, 
    TAG_STRING
} ValueTag;

typedef union { 
    bool as_bool;
    int64_t as_integer;
    double as_float;
    const char* as_string;
} ValuePayload;

typedef struct {
    ValueTag type;
    ValuePayload payload;
} Value;

The sizeof(Value) is 16-bytes/128-bits. It fits nicely into two hardware registers. The SYSV ABI also supports passing this structure and returning it without having to put it on the stack.

void foo(Value arg); 
// arg.type passed in first argument register
// arg.payload passed in second argument register

Value bar();
// result.type returned in first return register
// result.payload returned in second return register

On Windows/MSVC however, the ABI only supports a single 64-bit value passed and returned in a register - so a struct like this ends up being put onto the stack, which costs us a dereference for each access. This is where some of the techniques from Gudeman's paper are relevant - where we can store both the type and the value in a single 64-bit word.

If we have 64-bit integers, 64-bit floating point, and 64-bit pointers we can't store either of these, plus a type tag in the same machine word which is only 64-bits. We have to reduce the size of our values to make space for the type tag. Consider for example, we restrict the size of our values to 48-bits, and use a 16-bit type tag - this is sufficient for pointers (48-bits is the virtual address limit on most machines). We can store a single-precision float and 32-bit integer in the payload.

typedef enum : unsigned short { 
    TAG_NONE, 
    TAG_INT,
    TAG_FLOAT,
    TAG_POINTER
} ValueTag;

typedef struct {
    int64_t tagged_payload;
} Value;

typedef union { float as_float; int32_t as_int; } pun;

inline ValueTag value_get_type(Value value) {
    return (ValueTag)value.tagged_payload;
}
inline Value value_make_integer(int32_t value) {
    return (Value){ (int64_t)value << 32 | TAG_INT };
}
inline Value value_make_float(float value) {
    pun v = { .as_float = value };
    return (Value){ (int64_t)v.as_int << 32 | TAG_FLOAT };
}
inline Value value_make_pointer(void *ptr) {
    return (Value){ (int64_t)(intptr_t)ptr << 16 | TAG_POINTER };
}
inline int32_t value_get_integer(Value value) {
    assert(value_get_type(value) == TAG_INT);
    return (int32_t)(value.tagged_payload >> 32);
}
inline float value_get_float(Value value) {
    assert(value_get_type(value) == TAG_FLOAT);
    pun v = { .as_int = value.tagged_payload >> 32 };
    return v.as_float;
}
inline void *value_get_pointer(Value value) {
    assert(value_get_type(value) == TAG_POINTER);
    return (void*)(intptr_t)(value.tagged_payload >> 16);
}

Once we have a way of representing these types in this way, we can perform operations using these functions

Value add(Value lhs, Value rhs) {
    switch(value_get_type(lhs)) {
        case TAG_INT:
            switch (value_get_type(rhs)) {
                case TAG_INT:
                    return value_make_integer(add_int(value_get_int(lhs), value_get_int(rhs)));
                case TAG_FLOAT:
                    return value_make_float(add_float(int_to_float(value_get_int(lhs)), value_get_int(rhs)));
                ...
             }
        case TAG_FLOAT:
               switch (value_get_type(rhs)) {
                case TAG_INT:
                    return value_make_float(add_float(value_get_float(lhs), int_to_float(value_get_int(rhs))));
                case TAG_FLOAT:
                    return value_make_float(add_float(value_get_float(lhs), value_get_float(rhs)));
                ...
             }
         ...
    }
}

There are other ways we can do this such as using branch tables - but for a small number of a types a switch will probably be optimized better by the compiler.


A well-known technique that allows us to use a single machine register and still use a double is known as "NaN-boxing". It takes advantage of the fact that in a double-precision float, when all of the exponent bits are set to 1, the value is a NaN - the mantissa bits are irrelevant here, and there are 52 bits. 52-bits is sufficient space to store a 48-bit pointer, a 48-bit integer, and more - so we can still have a type tag and 48-bit payload in this 52-bits of space. We can do similar to the above, but we craft our type tags to only be those which are a NaN.

constexpr uint16_t NAN_BITS = 0x7FF0;
constexpr uint16_t SIGN_BIT = 0x8000;
constexpr uint16_t QNAN_BIT = 0x0008;

typedef enum : unsigned short { 
    TAG_POS_INFINITY = NAN_BITS,
    TAG_1,
    TAG_2,
    TAG_3,
    TAG_4,
    TAG_5,
    TAG_6,
    TAG_7,
    TAG_POS_QNAN = NAN_BITS | QNAN_BIT,
    TAG_NEG_INFINITY = NAN_BITS | SIGN_BIT,
    TAG_8,
    TAG_9,
    TAG_10,
    TAG_11,
    TAG_12,
    TAG_13,
    TAG_14,
    TAG_NEG_QNAN = NAN_BITS | QNAN_BIT | SIGN_BIT
} ValueTag;

This allows us to tag up to 14 different non-double types, with each having up to 48-bits of payload. However, we have to treat double specially - since it covers all other tags which are not these 14.

bool value_is_double(Value value) {
    return value_get_type(value) <= TAG_POS_INFINITY
        || value_get_type(value) >= TAG_POS_QNAN 
        && value_get_type(value) <= TAG_NEG_INFINITY
        || value_get_type(value) >= TAG_NEG_QNAN
}

Value value_make_double(double value) {
    return (Value){ .tagged_payload = rotate_left(value, 16) };
}

double value_get_double(Value value) {
    return (double)(rotate_right(value.tagged_payload, 16));
}

2

u/WittyStick 16d ago edited 15d ago

Hmm, post ended up longer than I expected and Reddit wouldn't let me add more.

Anyway, the NaN-boxing approach I shown above is just one method of doing it. I have not seen this specific approach (16-bit rotation) used in production VMs - but from my own experiments it's faster - the low 16-bits of a register are cheaper to compare than the high 16-bits - and it's also cheaper to recover a pointer or signed integer with this approach - using a single arithmetic shift right by 16-bits.

Value value_make_pointer(void *ptr) {
    return (Value){ .tagged_payload = (int64_t)(intptr_t)value << 16 | TAG_POINTER };
}
void *value_get_pointer(Value value) {
    return (void*)(intptr_t)(value.tagged_payload >> 16);
}

On some platforms like __arch64__, address canonicalization may not be used. We might need a logical right shift instead - so we could write it as:

void *value_get_pointer(Value value)
{
#ifdef __aarch64__
    return (void*)(intptr_t)((uint64_t)value.tagged_payload >> 16);
#else
    return (void*)(intptr_t)(value.tagged_payload >> 16);
#endif
}

Anyway, here's an example implementation of this style of NaN-boxing in Godbolt - compiling for x86-64 GCC, aarch64 Clang and x86-64 mingw

1

u/WittyStick 15d ago edited 15d ago

Here's a micro-optimization I've just discovered when playing with this a bit.

In the above example, where we have a switch on the tag in value_fprint.

switch (value_get_tag(value)) 

Both GCC and Clang convert this to a hybrid binary tree/jump table. Essentially, they notice that there are two consecutive ranges of tags, so they branch on this, then have a jump table in each branch. It's easier to see why if we write the actual tag values:

.left_branch:
TAG_UINT8 = 0x7FF1,
TAG_UINT16 = 0x7FF2,
TAG_UINT32 = 0x7FF3,
TAG_UINT48 = 0x7FF4,
TAG_UINT64_REF = 0x7FF5
TAG_FLOAT = 0x7FF6,
TAG_BOOLEAN = 0x7FF7

.right_branch:
TAG_INT8 = 0xFFF1,
TAG_INT16 = 0xFFF2,
TAG_INT32 = 0xFFF3,
TAG_INT48 = 0xFFF4,
TAG_INT64_REF = 0xFFF5,
TAG_STRING_REF = 0xFFF6,
TAG_OBJECT_REF = 0xFFF7,

Obviously these tags aren't consecutive, but there are two consecutive ranges. There is a way we can turn it into a single jump table and avoid a branch (which may mispredict). If we look at the tags without the NaN-bits, essentially we have a 4 bit tag, but the bits we use are not contiguous - we use the sign bit (most significant bit) and the 3 least significant bits.

TAG_POS_INF = 0x0000,
TAG_UINT8 = 0x0001,
TAG_UINT16 = 0x0002
TAG_UINT32 = 0x0003, 
TAG_UINT48 = 0x0004,
TAG_UINT64 = 0x0005,
TAG_FLOAT = 0x0006,
TAG_BOOLEAN = 0x0007,

TAG_NEG_INF = 0x8000,
TAG_INT8 = 0x8001,
TAG_INT16 = 0x8002,
TAG_INT32 = 0x8003,
TAG_INT48 = 0x8004,
TAG_INT64 = 0x8005,
TAG_STRING = 0x8006,
TAG_OBJECT = 0x8007,

It's not quite obvious, but there's an easy way to turn these tags into contiguous bits - a simple rotation left by 1. The three least significant bits shift left, and the most significant bit becomes the least significant bit. Let's give these a new name: a "Condensed tag" - a simple number 0..15 - much more suitable making a single jump table.

typedef enum : unsigned char {
    CTAG_POS_DOUBLE = 0x0000,
    CTAG_NEG_DOUBLE = 0x0001,
    CTAG_UINT8 = 0x0002,
    CTAG_INT8 = 0x0003,
    CTAG_UINT16 = 0x0004,
    CTAG_INT16 = 0x0005,
    CTAG_UINT32 = 0x0006,
    CTAG_INT32 = 0x0007,
    CTAG_UINT48 = 0x0008,
    CTAG_INT48 = 0x0009,
    CTAG_UINT64 = 0x000A,
    CTAG_INT64 = 0x000B,
    CTAG_FLOAT = 0x000C,
    CTAG_STRING = 0x000D,
    CTAG_BOOLEAN = 0x000E,
    CTAG_OBJECT = 0x000F,
} CondensedTag;

So to turn our original NaN-based tag into a condensed tag, we need to mask out the NAN-BITS and rotate left by 1 - but only if the value is not a double. (value_is_double unfortunately has two branches, so we don't want to use that). However, this approach works by using a conditional set:

condensed_tag = 
    ((tag & (NAN_BITS | QNAN_BIT)) == NAN_BITS) 
        ? __builtin_stdc_rotate_left((uint16_t)(tag &~ NAN_BITS), 1) 
        : 0

Basically, any double will become 0 except TAG_NEG_INFINITY which becomes 1. We have two tags for double but that's not a problem - we can have them both jump to the same code.

I would say we're done, but the compilers still try and be too clever and test for both negative/positive double first, before branching on the other 14 tags (because they share the same jump destination and the compiler is prioritizing CSE/code size). So there's still an unwanted branch. Even when we rewrite to not use a switch, but a jump table with the GCC extension labels-as-values, it tries to be smart again.

But if we use a horrible trick - __asm__ volatile("":::"memory"); to prevent the compiler trying to optimize over the boundary of computing the tag and branching, we can eventually get it to use a single branch table on the condensed tag. All this to save a branch or two.

int value_fprint(FILE *restrict stream, Value value)
{
    const static void *jt[] =
    {
        [CTAG_POS_DOUBLE] = &&lbl_dbl,
        [CTAG_NEG_DOUBLE] = &&lbl_dbl,
        [CTAG_UINT8] = &&lbl_uint8,
        [CTAG_INT8] = &&lbl_int8,
        [CTAG_UINT16] = &&lbl_uint16,
        [CTAG_INT16] = &&lbl_int16,
        [CTAG_UINT32] = &&lbl_uint32,
        [CTAG_INT32] = &&lbl_int32,
        [CTAG_UINT48] = &&lbl_uint48,
        [CTAG_INT48] = &&lbl_int48,
        [CTAG_UINT64] = &&lbl_uint64,
        [CTAG_INT64] = &&lbl_int64,
        [CTAG_FLOAT] = &&lbl_float,
        [CTAG_STRING] = &&lbl_string,
        [CTAG_BOOLEAN] = &&lbl_boolean,
        [CTAG_OBJECT] = &&lbl_object,
    };

    ValueType tag = value_get_tag(value);
    CondensedTag condensed = ((tag & (NAN_BITS | QNAN_BIT)) == NAN_BITS)
        ? __builtin_stdc_rotate_left((uint16_t)(tag &~ NAN_BITS), 1)
        : 0;

    // Outsmart the compiler!
    __asm__ volatile("":::"memory");

    goto *jt[condensed];

lbl_dbl: return fprintf(stream, "%.2f : Double", value_get_double(value));
lbl_uint8: return fprintf(stream, "%" PRIu8 " : UInt8", value_get_uint8(value));
lbl_int8: return fprintf(stream, "%" PRIi8 " : Int8", value_get_int8(value));
lbl_uint16: return fprintf(stream, "%" PRIu16 " : UInt16", value_get_uint16(value));
lbl_int16: return fprintf(stream, "%" PRIi16 " : Int16", value_get_int16(value));
lbl_uint32: return fprintf(stream, "%" PRIu32 " : UInt32", value_get_uint32(value));
lbl_int32: return fprintf(stream, "%" PRIi32 " : Int32", value_get_int32(value));
lbl_uint48: return fprintf(stream, "%llu : UInt48", (unsigned long long)value_get_uint48(value));
lbl_int48: return fprintf(stream, "%lli : Int48", (long long)value_get_int48(value));
lbl_uint64: return fprintf(stream, "%" PRIu64 " : UInt64", value_get_uint64(value));
lbl_int64: return fprintf(stream, "%" PRIi64 " : Int64", value_get_int64(value));
lbl_float: return fprintf(stream, "%0.1f : Float", value_get_float(value));
lbl_string: return fprintf(stream, "\"%s\" : String", value_get_string(value));
lbl_boolean: return fprintf(stream, "%s : Boolean", value_get_boolean(value) ? "true" : "false");
lbl_object:
    Object obj = value_get_object(value); 
    return obj->vtable->fprint(stream, obj);
}

Now we get a nice single branch on the tag - with relatively few instructions:

"value_fprint":
    mov     edx, esi
    mov     eax, esi
    and     dx, 0x7ff8 ;; NAN_BITS | QNAN_BIT
    rol     ax
    and     eax, 31
    cmp     dx, 0x7ff0 ;; NAN_BITS
    mov     edx, 0
    cmovne  eax, edx
    jmp     [QWORD PTR "jt.0"[0+rax*8]]

The obvious next step then, is to handle the "multiple dispatch" - at least for binary operations. If we have a 4-bit tag for single dispatch, then we can do double-dispatch with an 8-bit tag - a 256-entry jump table shouldn't be too bad. We can specialize each arithmetic operation for every pair of types - so eg, uint8 * double and double * uint8 will have their own labels.

lbl_uint8_double: return value_make_double(value_get_uint8(lhs) * value_get_double(rhs));
lbl_double_uint8: return value_make_double(value_get_double(lhs) * value_get_uint8(rhs));

You could probably generate these labels and the jump table with a few macros and an X macro.

Since all these calls are inlined, there should be no additional branch - ie, we could have single-branch double-dispatch. I can't say for sure whether this will be faster than using an extra branch or two though - would need benchmarking.

This is the assembly that GCC produces to condense two tags, combine them and dispatch on the index. It's clever enough to combine the left rotate by 1 and shift left by 4 into a single rotate left by 5, which was a nice surprise.

static inline uint8_t get_double_dispatch_index(Value lhs, Value rhs) {
    ValueType left_tag = value_get_tag(lhs);
    CondensedTag condensed_left = ((left_tag & (NAN_BITS | QNAN_BIT)) == NAN_BITS)
        ? __builtin_stdc_rotate_left((uint16_t)(left_tag &~ NAN_BITS), 1)
        : 0;
    ValueType right_tag = value_get_tag(rhs);
    CondensedTag condensed_right = ((right_tag & (NAN_BITS | QNAN_BIT)) == NAN_BITS)
        ? __builtin_stdc_rotate_left((uint16_t)(right_tag &~ NAN_BITS), 1)
        : 0;
    return condensed_left << 4 | condensed_right;
}

"get_double_dispatch_index":
        mov     eax, edi ;; lhs
        rol     di, 5
        mov     edx, esi ;; rhs
        and     ax, 0x7ff8
        and     edi, 0xfff0
        cmp     ax, 0x7ff0
        mov     eax, 0
        cmove   eax, edi
        and     si, 0x800f
        and     dx, 0x7ff7
        rol     si
        or      esi, eax
        cmp     dx, 0x7ff0
        cmove   eax, esi
        ret

15 instructions, 1 branch and 1 dereference (of the jump table) to do double-dispatch on 15 different types.

2

u/roeschinc 16d ago

One thing people often get tripped up on in the beginning is one language isn’t “faster” than another, so rewriting any piece of code to C++ doesn’t guarantee it will be faster.

This also extends to compilation versus interpretation. Depending on the characteristics of the language semantics you can write a slow compiler or a fast interpreter and vice versa.

It comes down to understanding what is slow about certain language semantics and what kind of optimizations can be performed to speed them up.

As others have said Python has decades of performance optimization to remove the cost of interpreting the bytecode, so your compiler must first match that performance in terms of optimization and then go further beyond that.

At a high level Python (and most interpreted languages) the main costs are lack of typing, dynamic execution semantics (function calls can be 10-100x slower easily), interpreter overhead, and then weak or inefficient programming patterns.

For example a single Python function using strings or dicts will usually beat most hand-written code because those primitives are actually incredibly well-tuned pieces of C code that execute in the runtime.

One concrete example is Python has heavily optimized the memory representation, runtime type information, and virtual dispatch for objects. Using C++ builtins to emulate the same behavior is likely to be worse for a number of reasons.

If you want a deeper understanding you can likely find a few books / chat with an LLM to explain how they implement these efficiently.

2

u/realrealvantheman 16d ago edited 16d ago

Because CPython has had decades of optimization work done by the best in the field. That simple. If there is a trick that exists, it is probably implimented in CPython, Lua, Linux, or another giant. I mostly work in C and assembler and would probably not be able to make much sense of the codebase of yours if I read it, so I cant help on that. (I cant read c++ very well lol)

1

u/AustinVelonaut 16d ago

The Double dispatch mechanism is a clean way to dispatch to an ultimate binary operation (it was used heavily in Smalltalk implementations, too), and it handles all combinations of operand types, but it does require three indirect jumps for each operation. Since it is much more common to encounter a binary operation on two of the same type, most systems check for the common same-type case first, e.g. try a quick check of Int/Int, then call int.op directly, otherwise fall back to double-dispatch.

1

u/Dan13l_N 15d ago

TBH this is very weird. Python is really slow. My toy (statically typed) language is often 10 x faster than Python.

Are you sure you are building your benchmarks with maximum optimization level?

Also, what benchmarks are you using? In my experience, only looping a million times -- or some big number like that -- over a section of code will give you some real numbers.

0

u/[deleted] 16d ago edited 16d ago

There are reasons why CPython uses C rather than C++. With C it has much more control.

But, you don't yet have an actual interpreter loop, just type dispatch?

So, what is the actual task being compared, and how slower is your backend than CPython? How is it being measured?

CPython is generally considered slow, and difficult to speed up because of how dynamic Python is and being able to overload operators and so on. But I don't know how much of that applies to your tests.

To perform operations between two unknown dynamic types, the project implements a two-step resolution mechanism:

My own type dispatch is brisker than CPython and is simple (but I don't have arbitrary overloads).

So if I'm doing ADD between A and B for example, then I first do a quick check to see if they both are ints or both floats, otherwise the next check is whether they the same type, then only single dispatch is needed.

1

u/rileyrgham 16d ago

No C doesn't have much more control.

1

u/WittyStick 16d ago edited 16d ago

You're right, you can do pretty much anything C can do in C++ too - it's mostly (but not entirely) a superset. GP should've probably worded it as "With C, you are in control".

By that, it means you aren't relying on classes and templates provided by C++ - but basically implementing the equivalent functionality yourself with PODs and functions. The features added by C++ aren't really suitable for optimizing dynamic types. Even if you're using a C++ compiler, you'll use the mostly C-compatible subset to implement dynamic types.

Classes are not a good choice for dynamic types due to the way C++ implements virtual dispatch, and classes without virtual dispatch are just fancy structs with functions that require a specific convention that occupies a whole register for this. We can do better with more compact type tagging schemes.

Templates are not a good choice for dynamic types, because each template instance is its own static type - but in a dynamic type system, you specifically have one static type to hold all dynamic values - eg, like std::any, or a specific instance of std::variant for a limited set of types - but you can do better than std:any or std::variant.

There's nothing really that C++ provides over C that makes implementing dynamic types any more efficient. It can be useful to use classes and templates in other parts of the implementation of a dynamic language interpreter though, so there's nothing wrong with using a C++ compiler. C just discourages you from using C++'s non-zero-cost abstractions and implement the functionality yourself, optimized for your language.