stride3d / stride

Stride (formerly Xenko), a free and open-source cross-platform C# game engine.
https://stride3d.net
MIT License
6.65k stars 957 forks source link

optimize method in GeometricPrimitive.Torus.New ,avoid GC ( list2array ) #2366

Closed Arc-huangjingtong closed 5 months ago

Arc-huangjingtong commented 5 months ago

PR Details

optimize method in GeometricPrimitive.Torus.New(...) it will avoid GC form List2Array

Related Issue

Types of changes

Checklist

IXLLEGACYIXL commented 5 months ago

please fil the formular, we have a summary foreach release, so people can click on your PR and read what it is about without reading the code changes

Arc-huangjingtong commented 5 months ago

In this func , has some fix

- if (tessellation < 3) tessellation = 3;
+ tessellation = Math.Max(3, tessellation); //more concise
- var vertices = new List<VertexPositionNormalTexture>();
- var indices = new List<int>();

//because the array size is definite , dont new list and toArray,it will be quickly
+ VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[stride * stride];
+ int[] indices = new int[tessellation * tessellation * 6];

+ var indexerIndices   = 0;
+ var indexerVertices  = 0;

  ...
+ vertices[indexerVertices++] = ....

+ indices[indexerIndices++] = i * stride + j;
+ indices[indexerIndices++] = i * stride + nextJ;
+ indices[indexerIndices++] = nextI * stride + j;

+ indices[indexerIndices++] = i * stride + nextJ;
+ indices[indexerIndices++] = nextI * stride + nextJ;
+ indices[indexerIndices++] = nextI * stride + j;

- return new GeometricMeshData<VertexPositionNormalTexture>(vertices.ToArray(), indices.ToArray(),toLeftHanded) { Name = "Torus" };
+ return new GeometricMeshData<VertexPositionNormalTexture>(vertices, indices, toLeftHanded) { Name = "Torus" };
Arc-huangjingtong commented 5 months ago

please fil the formular, we have a summary foreach release, so people can click on your PR and read what it is about without reading the code changes

yes , i done 😄

IXLLEGACYIXL commented 5 months ago

the pr details would be about what its changing overall

a description

Arc-huangjingtong commented 5 months ago

the pr details would be about what its changing overall公关细节将是关于它的整体变化

a description 描述

Sorry ,now i get it 😿

Ethereal77 commented 5 months ago

Anyway, nice change. I think it would be nice to extend this same change to the other GeometricPrimitives.

Arc-huangjingtong commented 5 months ago

Anyway, nice change. I think it would be nice to extend this same change to the other GeometricPrimitives.总之,不错的变化。我认为将相同的更改扩展到其他 GeometricPrimitive s 会很好。

yes , if this pr success ,i will modified others

IXLLEGACYIXL commented 5 months ago

why closed?

Arc-huangjingtong commented 5 months ago

why closed?

because i operate worrying , i will recommit in beijing time(utc➕8) night

Arc-huangjingtong commented 5 months ago

why closed? 为什么关闭?

because i operate worrying , i will recommit in beijing time(utc➕8) night因为我担心,我会在北京时间(UTC➕8)晚上重新承诺

sorry I may not be able to fulfill my agreement

Arc-huangjingtong commented 5 months ago

I'm a little under the weather

IXLLEGACYIXL commented 5 months ago

no hurry :D