GithubHelp home page GithubHelp logo

faster_expression_evaluation's Introduction

场景

用于对请求进行规则匹配、活动资格匹配、限频条件匹配等需要进行条件表达式进行求值的场景

调用方式

Calculater cal;
	cal.SetNum("varnum",12);
	cal.SetNum("varnuma",1);
	cal.SetString("varstring","a");
	cal.SetString("varstringb","c");
	int ret = cal.Cal("(varnum==12 || 1==2) && (varstring>=\"b\" || varstringb<\"d\")",msg);
 //ret<0:错误; ==0表达式结果为false; ==1表达式结果为true

特性

  1. 超高性能,上述例子单核200000 qps, 多核性能线性增长(8核约160W qps)。实测超过LUA 10倍
  2. 手写词法解析、语法解析
  3. 对象池优化、算符查找静态化,加强性能。

优化过程

  1. 初始60000 qps
  2. 发现大量临时小对象分配
    1. 容器中TOKEN对象全部改为指针,所有TOKEN存放在一个vector中,其他地方指针指过来
    2. 计算开始和结束会分析TOKEN,有对象生成和销毁,改为对象池分配
    3. 改造后,提升到12W
  3. 发现算符匹配耗时
    1. 算符匹配最开始是个map,改为hash_map,最终利用算符只可能是ascii以及最多是二元操作符,改为查表,用一个128*129的数组实现
    2. 改造后,提升到20W

faster_expression_evaluation's People

Contributors

redwood9 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.