Repository: valkey-io/valkey
File: src/server.c (C)

Code before:
        server.el_start = getMonotonicUs();
        /* Set the eventloop command count at start. */
        server.el_cmd_cnt_start = server.stat_numcommands;
    }

    /* Update the time cache. */
    updateCachedTime(1);

    /* Update command time snapshot in case it'll be required without a command
     * e.g. somehow used by module timers. Don't update it while yielding to a
     * blocked command, call() will handle that and restore the original time. */
    if (!ProcessingEventsWhileBlocked) {
        server.cmd_time_snapshot = server.mstime;
    }

    adjustIOThreadsByEventLoad(numevents, 0);
}

/* =========================== Server initialization ======================== */

static inline robj *createSharedString(const char *string) {
    return makeObjectShared(createStringObject(string, strlen(string)));
}

static inline robj *createSharedStringByPtr(void *ptr) {
    return makeObjectShared(createObject(OBJ_STRING, ptr));
}

/* These shared strings depend on the extended-redis-compatibility config and is
 * called when the config changes. When the config is phased out, these
 * initializations can be moved back inside createSharedObjects() below. */
void createSharedObjectsWithCompatNo(void) {
    const char *name = SERVER_TITLE;
    shared.loadingerr_valkey =
        createSharedStringByPtr(sdscatfmt(sdsempty(), "-LOADING %s is loading the dataset in memory\r\n", name));
    shared.slowevalerr_valkey = createSharedStringByPtr(
        sdscatfmt(sdsempty(),
                  "-BUSY %s is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.\r\n", name));
    shared.slowscripterr_valkey = createSharedStringByPtr(
        sdscatfmt(sdsempty(),
                  "-BUSY %s is busy running a script. You can only call FUNCTION KILL or SHUTDOWN NOSAVE.\r\n", name));
    shared.slowmoduleerr_valkey =
        createSharedStringByPtr(sdscatfmt(sdsempty(), "-BUSY %s is busy running a module command.\r\n", name));
    shared.bgsaveerr_valkey =
        createSharedStringByPtr(sdscatfmt(sdsempty(),
                                          "-MISCONF %s is configured to save RDB snapshots, but it's currently"
                                          " unable to persist to disk. Commands that may modify the data set are"
                                          " disabled, because this instance is configured to report errors during"
                                          " writes if RDB snapshotting fails (stop-writes-on-bgsave-error option)."
                                          " Please check the %s logs for details about the RDB error.\r\n",
                                          name, name));

Review comment (suggestion):
ptr is sds, right?

```suggestion
static inline robj *createSharedStringBySds(sds *s) {
    return makeObjectShared(createObject(OBJ_STRING, s));
```

Code after:
        server.el_start = getMonotonicUs();
        /* Set the eventloop command count at start. */
        server.el_cmd_cnt_start = server.stat_numcommands;
    }

    /* Update the time cache. */
    updateCachedTime(1);

    /* Update command time snapshot in case it'll be required without a command
     * e.g. somehow used by module timers. Don't update it while yielding to a
     * blocked command, call() will handle that and restore the original time. */
    if (!ProcessingEventsWhileBlocked) {
        server.cmd_time_snapshot = server.mstime;
    }

    adjustIOThreadsByEventLoad(numevents, 0);
}

/* =========================== Server initialization ======================== */

static inline robj *createSharedString(const char *string) {
    return makeObjectShared(createStringObject(string, strlen(string)));
}

static inline robj *createSharedStringFromSds(sds s) {
    return makeObjectShared(createObject(OBJ_STRING, s));
}

/* These shared strings depend on the extended-redis-compatibility config and is
 * called at initialization. When the config is phased out, these
 * initializations can be moved back inside createSharedObjects() below. */
void createSharedObjectsForCompat(int compat) {
    const char *name = compat ? "Redis" : SERVER_TITLE;
    shared.loadingerr_variants[compat] =
        createSharedStringFromSds(sdscatfmt(sdsempty(), "-LOADING %s is loading the dataset in memory\r\n", name));
    shared.slowevalerr_variants[compat] = createSharedStringFromSds(
        sdscatfmt(sdsempty(),
                  "-BUSY %s is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.\r\n", name));
    shared.slowscripterr_variants[compat] = createSharedStringFromSds(
        sdscatfmt(sdsempty(),
                  "-BUSY %s is busy running a script. You can only call FUNCTION KILL or SHUTDOWN NOSAVE.\r\n", name));
    shared.slowmoduleerr_variants[compat] =
        createSharedStringFromSds(sdscatfmt(sdsempty(), "-BUSY %s is busy running a module command.\r\n", name));
    shared.bgsaveerr_variants[compat] =
        createSharedStringFromSds(sdscatfmt(sdsempty(),
                                            "-MISCONF %s is configured to save RDB snapshots, but it's currently"
                                            " unable to persist to disk. Commands that may modify the data set are"
                                            " disabled, because this instance is configured to report errors during"
                                            " writes if RDB snapshotting fails (stop-writes-on-bgsave-error option)."
                                            " Please check the %s logs for details about the RDB error.\r\n",
                                            name, name));