Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOS optimization #117

Closed
tmptrash opened this issue Feb 16, 2018 · 0 comments
Closed

DOS optimization #117

tmptrash opened this issue Feb 16, 2018 · 0 comments

Comments

@tmptrash
Copy link
Owner

tmptrash commented Feb 16, 2018

  1. Можно оптимизировать интерпретатор в значительной мере. Сейчас мы парсим бинарный байт код каждый раз перед выполнением (по сути, парсим каждую строку). Нужно делать это один раз (первый и после каждого изменения кода) причем допарсывать можно только ту строку, которая была изменена. Разпарсанная версия будет сохранятся в еще один исполняемый байткод. Он будет состоять из обычного массива той же длины, что и оригинальный байт код, только его элементами будут функции исполнения. Например:
    0x0213ffff -> if(v0 < v1) goto 255. Внутри onCondition() мы берем Num.getVarX(), Num.getBits() и т.д. Нужно заранее иметь все варианты onCondition() со всеми вариантами переменных внутри. Варианты можно сгенерировать при старте программы с помощью шаблонов и eval(). Например код:

        onVar(num, line, org) {
            this.vars[Num.getVar0(num)] = this.vars[Num.getVar1(num)];
            org.energy -= OConfig.orgOperatorWeights[0];
            return ++line;
        }

    можно заменить на шаблон:

       const template = `
        onVar(num, line, org) {
            this.vars[${var0}] = this.vars[${var1}];
            return ++line;
        }`;

    В результате будет выполнятся скомпилированный шаблон. Он будет значительно быстрее.

  2. Еще можно оптимизировать выполнение кода передав классу Operators ссылки на world, positions и organisms. Тогда, не нужно будет генерировать событие во вне (в Organisms плагин), можно все делать прямо на месте (внутри класса Operators)

связано с #135 #90 #92 #67

@tmptrash tmptrash added this to the v0.2.2 DOS improvements milestone Feb 16, 2018
@tmptrash tmptrash self-assigned this Feb 16, 2018
@tmptrash tmptrash added the idea label Feb 16, 2018
tmptrash added a commit that referenced this issue Apr 5, 2018
in progress with new DOS operators and VM #135, #117, #67
tmptrash added a commit that referenced this issue Apr 5, 2018
in progress with new DOS operators and VM #135, #117, #67
application speed up using FastArray
tmptrash added a commit that referenced this issue Apr 7, 2018
tmptrash added a commit that referenced this issue Apr 13, 2018
refactored plugins: Energy, Stones, Objects
added commands: eat, put, energy, pick
updated color scheme
refactored configs
improved if operator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant