Performance Bottleneck with Group.get() Method in Phaser

Đang mở
#7,140 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
javascript
Lĩnh vực
game-dev, performance

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện các lệnh gọi lặp lại tới Group.get() từ main.js với một group lớn, sau đó kiểm tra phần triển khai Group.get() của Phaser và so sánh thời gian với phần thiết lập SeedItem trong SeedItem.js. Xác định xem chi phí nằm ở object pooling hay ở việc khởi tạo, và xác định việc hoàn thành là một cải thiện hiệu năng được chứng minh mà vẫn duy trì hành vi dự kiến của các đối tượng trong pool.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Problem Description

I'm experiencing significant performance issues with the Group.get() method in Phaser. The method takes an unusually long time to execute, especially when the group contains a large number of objects. This significantly impacts the performance of my application.

Code Snippets

main.js (Relevant Part)
const seedItems = scene.add.group({
    classType: SeedItem,
    maxSize: -1,
    runChildUpdate: false
});

this.fillItems = (itemClass, itemDataList, cols = 6, itemWidth = 181, itemHeight = 201) => {
    const panel = scrollList.getElement('panel');
    const line = Math.ceil(itemDataList.length / cols);

    itemDataList.forEach((data, index) => {
        const row = Math.floor(index / cols);
        const col = index % cols;
        const x = col * (itemWidth + 20) + 160;
        const y = row * (itemHeight + 30) + 110;
        let start = performance.now();
        const seedItem = seedItems.get();
        console.log("cost", performance.now() - start);
        if (seedItem) {
            seedItem.updateData(x, y, data);
            seedItem.setActive(true);
            seedItem.setVisible(true);
            panel.add(seedItem);
        }
     
    });

    panel.setSize(GameConfig.Screen.width, (itemHeight + 30) * line + 30);
    scrollList.layout();
};
SeedItem.js (Simplified and Sanitized)
export default class SeedItem extends Phaser.GameObjects.Container {
    constructor(scene, x, y, children) {
        super(scene, x, y, children);
        // UI elements initialization
        this.bg = scene.add.image(0, 0, "item_atlas", "item_bg.png").setInteractive({ useHandCursor: true });
        this.icon = scene.add.image(0, 0, "common_atlas", "icon_seed_default.png");
        this.levelText = scene.add.text(-70, -95, "", { fontFamily: "Arial", fontSize: "24px", fill: "#ffffff" });
        this.countText = scene.add.text(45, 35, "", { fontFamily: "Arial", fontSize: "24px", fill: "#385bb6" });
        this.nameText = scene.add.text(0, 85, "", { fontFamily: "Arial", fontSize: "22px", fill: "#fffffb" }).setOrigin(0.5, 0.5);
        this.notBuyBg = scene.add.image(0, 0, "item_atlas", "item_not_available.png").setVisible(false);

        // Event listeners
        this.bg
            .on("pointerdown", (pointer) => { /* ... */ })
            .on("pointermove", (pointer) => { /* ... */ })
            .on("pointerup", (pointer) => { /* ... */ });
    }

    updateData(x, y, data) {
        this.setPosition(x, y);
        const { level, count, name, type } = data;
        this.levelText.setText(`Lv.${level}`);
        this.countText.setText(count);
        this.nameText.setText(name);
    }
}

Steps to Reproduce

  1. Create a group with maxSize: -1.
  2. Repeatedly call group.get() in a loop (e.g., for populating a grid).
  3. Observe the execution time of each get() call.

Expected Behavior

The get() method should return a pooled object quickly, even for large groups.

Possible Workarounds

  • Pre-warm the pool by pre-creating objects.
  • Limit the group size if possible.

Could you investigate this issue or suggest optimizations? Thanks!

Ngôn ngữ chính
JavaScript
Star
40.7k
Fork
7.2k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của phaserjs/phaser

Tất cả issue của phaserjs/phaser

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.