V8 引擎升级11.6

官方有计划升级native v8么,这边模拟器测试 v8 升级后 js 运行性能会有很大的提升 前面雷电模拟器跑 polybooljs 逻辑 100ms现在只要跑1ms 基本和浏览器是一个性能

在问个问题 怎么样配置gn编译参数才能把libinspector和libv8_monolith分开编译成静态库,现在用v8_monolithic = true 只能编译出一个libv8_monolith 然后libinspector内容也会在这里面

5赞

给你顶一下,不明觉厉

3赞

帮顶一下,请官方关注

帮顶一下,请官方关注

v8.dev版本不是才到9.9么?

我们安卓测试结果没有变化那么大,iOS 变化不大,详见 https://github.com/cocos/cocos-engine/issues/15552

你们的测试结果可以详细介绍一下?

大家都顶一下 :+1:

20感觉提升很多了,不知道机型是什么级别的。

image
https://github.com/v8/v8.git
不知道你在哪弄的,我是这里clone 的

interface RegionInfo {
    region : Vec2[],
    parentCount : number,
}
// 合并用户点击产生的多边形
@ccclass('PolyBoolComponent')
export class PolyBoolComponent extends Component {
    @property
    DIG_FRAGMENT = 30;
    @property
    DIG_RADIUS = 30;
    _segment:PolyBool.Segment
    regionsDirty: boolean = true;
    start() {
    }

    reset() {
        let size = this.node.getComponent(UITransform).contentSize;
        let w = size.width/2;
        let h = size.height/2;
        let regions = [[
            [-w,-h],
            [-w,h],
            [w,h],
            [w,-h],
        ]]

        this.setRegions(regions)
    }

    private get graphics() {
        return this.node.getComponent(Graphics)
    } 

    setRegions(regions: number[][][]) {
        this._segment = PolyBool.segments({
            regions: regions,
            inverted: false
        })
        // 强制渲染避免闪屏
        this.regionsDirty = false;
        let regionsInfo:RegionInfo[] = this.sortRegions(PolyBool.polygon(this._segment).regions);
        this.draw(regionsInfo);
    }

    getRegions() {
        return PolyBool.polygon(this._segment).regions;
    }

    expandLine(p1: Vec2, p2: Vec2, width: number): [Vec2, Vec2, Vec2, Vec2] {
        const v = p2.clone().subtract(p1).normalize()
        const u = new Vec2(-v.y,v.x).multiplyScalar(width)
        const p1_ = p1.clone().add(u)
        const p2_ = p1.clone().subtract(u)
        const p3_ = p2.clone().subtract(u)
        const p4_ = p2.clone().add(u)
        return [p1_, p2_, p3_, p4_];
    }
    
	@addRunTime("_touchMove")
    _touchMove(spos:IVec2Like,epos:IVec2Like) {
        this.regionsDirty = true;
        const regions = [];

        const count = this.DIG_FRAGMENT;
        {
            let region = []
            for (let index = 0; index < count; index++) {
                const r = 2 * Math.PI * index / count;
                const x = epos.x + this.DIG_RADIUS * Math.cos(r);
                const y = epos.y + this.DIG_RADIUS * Math.sin(r);
                region.push([x, y]);
            }
            regions.push(region)
        }
        
        if(spos.x != spos.x || spos.y != epos.y) {
            let region = []
            this.expandLine(new Vec2(spos.x,spos.y),new Vec2(epos.x,epos.y),this.DIG_RADIUS).forEach(v=>{
                region.push([v.x, v.y]);
            })
            regions.push(region)
        }

        regions.forEach(v=>{
            let seg2  = PolyBool.segments({
                regions:[v],
                inverted: false
            });
            let comb = PolyBool.combine(this._segment, seg2);
            this._segment = PolyBool.selectDifference(comb)
        })
    }

    sortRegions(regions:number[][][]) {
        let regionsInfo:RegionInfo[] = [];
        regions.forEach((region,index)=>{
            regionsInfo[index] = {
                region : region.map(v=>{
                    return new Vec2(v[0],v[1]);
                }),
                parentCount : 0,
            } 
        })

        regionsInfo.forEach((curRegionInfo,curIndex)=>{
            regionsInfo.forEach((regionInfo,index)=>{
                if(curIndex!=index) {
                    let point = curRegionInfo.region[0]
                    if(Intersection2D.pointInPolygon(point,regionInfo.region)) {
                        curRegionInfo.parentCount++;
                    }
                }
            })
        })
        regionsInfo.sort((a, b) => {
            return a.parentCount - b.parentCount;
        })
        return regionsInfo;
    }

    protected lateUpdate(dt: number): void {
        if(this.regionsDirty) {
            this.regionsDirty = false;
            let regionsInfo:RegionInfo[] = this.sortRegions(PolyBool.polygon(this._segment).regions);
            this.draw(regionsInfo);
        }
    }

    draw(regionsInfo:RegionInfo[]) {
        let graphics = this.graphics
        graphics.clear()
        graphics.lineWidth = 5;
        regionsInfo.forEach(regionInfo=>{
            graphics.fillColor = color(255 - regionInfo.parentCount % 2 * 255, 0, 0);
            let region = regionInfo.region
            graphics.moveTo(region[0].x, region[0].y);
            for (let index = 1; index < region.length; index++) {
                const element = region[index];
                graphics.lineTo(element.x, element.y);
            }
            graphics.close();
            // graphics.stroke();
            graphics.fill();
        })
    }
}

相同的js代码都是 arm64 的 在 雷电模拟器上跑的结果
image
image


其他的话就是相同流程下进游戏的时间缩短了,用devtools 性能分析 js 和 c++交互的时间没有啥变化,变化比较大的还是js运行的效率,看官方文档9.1以后有几次性能提升的优化,关于机型的话我们自己买的手机其实都不卡,卡的是模拟器(蓝叠不卡)和低端机会比较卡,尤其是大量创建节点和polybooljs合并多边形的时候,目前看升级后polybooljs的问题能解决,大量创建节点还是老样子,ps(同一时间创建1000个渲染节点)

1赞

哦哦,github上确实到11了,我看的是v8.dev上的blog,应该是周更的版本没有必要在上面同步的。

看了你发的测试是没有太大提升,我这边没走测试用例 主要还是跑自己的项目在相同cpu架构和js代码下的运行结果来测的,主要是优化我们在低端机上面运行卡顿的问题,因为我们的项目运行环境低端机比较多所以需要优化性能,我们是从cocoslua转过来的,目前看来lua版本的运行结果会好很多

不明觉厉。

项目转到creator 3.x 确实遇到了很多问题,用户录了个视频我们机子1-2秒进的游戏在用户手机上跑了13秒才进去,差点提桶跑路了

性能优化在低端机上体现得可能更明显,高端机上没那么明显

20%的性能提升不小了吧 :astonished:

现在的手机CPU每年提升都只有个位数

你们在cocos2dx上是开启luajit的么?

开了呀,怎么了

知道怎么把libinspector.a 和 libv8_monolith.a 分开么 我现在编译的只有一个libv8_monolith.a,找了好久编译参数没找到能分开编译的 ar 看了下 现在生成的一个libv8_monolith.a包含里 inspector 的全部.o文件