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

Bugfix/merged optimizations #578

Closed
wants to merge 4 commits into from
Closed

Conversation

maerki
Copy link
Contributor

@maerki maerki commented Jan 24, 2024

Summary by CodeRabbit

  • Performance Improvements

    • Improved rendering efficiency for 2D graphics elements with conditional OpenGL buffer generation.
    • Optimized rendering intervals for smoother graphics performance.
  • New Features

    • Enhanced map tile loading with a debounced trigger mechanism for improved user experience.
  • Refactor

    • Streamlined evaluation flow in ValueEvaluator for more consistent value processing.
    • Updated Tiled2dMapVectorSymbolObject with method return type refinement and removed duplicate code.

maurhofer-ubique and others added 4 commits January 24, 2024 12:49
…s in source tile data manager on update, allow more gl tasks on pre-render (within given time constraint), don't cache zoom-dependent values (prevent cache overflow)
Copy link
Contributor

coderabbitai bot commented Jan 24, 2024

Walkthrough

The updates across various files in an Android graphics-related codebase include conditional OpenGL buffer generation, adjusted rendering intervals based on timing, and enhanced tile loading in a mapping source. Additionally, there have been refinements in value evaluation logic and changes to symbol object instance count return types, suggesting an overall improvement in graphics rendering efficiency and data handling.

Changes

File Path Summary
.../graphics/objects/Quad2dInstancedOpenGl.cpp
.../graphics/objects/Quad2dStretchedInstancedOpenGl.cpp
.../graphics/objects/Text2dInstancedOpenGl.cpp
Conditional OpenGL buffer generation if not previously created.
.../mapscore/graphics/GLThread.kt Introduced finishDuration for managing rendering intervals.
.../Tiled2dMapSource.h
.../Tiled2dMapSourceImpl.h
Added methods and members for tile loading and update notification logic.
shared/public/Value.h Updated control flow in ValueEvaluator class to use a local variable.
.../tiled/vector/symbol/Tiled2dMapVectorSymbolObject.h Removed duplicate method and updated return type for getInstanceCounts.

Poem

🐇✨
In the realm of code where the pixels play,
Buffers arise if not there before today.
Tiles load with care, new frames unfurl,
A rabbit hops through the digital swirl. 🌌🚀
🐇✨

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@maerki maerki closed this Jan 24, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 8

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c185fae and 50da5a7.
Files selected for processing (8)
  • android/src/main/cpp/graphics/objects/Quad2dInstancedOpenGl.cpp (1 hunks)
  • android/src/main/cpp/graphics/objects/Quad2dStretchedInstancedOpenGl.cpp (1 hunks)
  • android/src/main/cpp/graphics/objects/Text2dInstancedOpenGl.cpp (1 hunks)
  • android/src/main/java/io/openmobilemaps/mapscore/graphics/GLThread.kt (1 hunks)
  • shared/public/Tiled2dMapSource.h (2 hunks)
  • shared/public/Tiled2dMapSourceImpl.h (1 hunks)
  • shared/public/Value.h (1 hunks)
  • shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.h (1 hunks)
Additional comments: 9
shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.h (1)
  • 61-61: The getInstanceCounts method's return type has been changed to a non-const value.

This change is acceptable if the intention is to allow modification of the returned SymbolObjectInstanceCounts object.

android/src/main/cpp/graphics/objects/Quad2dInstancedOpenGl.cpp (1)
  • 105-111: Conditional OpenGL buffer generation logic has been added.

This is a good optimization to prevent unnecessary buffer generation.

android/src/main/cpp/graphics/objects/Text2dInstancedOpenGl.cpp (1)
  • 104-111: Conditional OpenGL buffer generation logic has been added.

This is a good optimization to prevent unnecessary buffer generation.

android/src/main/cpp/graphics/objects/Quad2dStretchedInstancedOpenGl.cpp (2)
  • 106-112: The addition of new OpenGL buffers is consistent with the PR objectives to optimize the OpenGL rendering process. However, ensure that the rest of the codebase is updated to utilize these new buffers, and that any necessary cleanup is performed to remove old buffer usage if it has been replaced by this new implementation.
  • 106-112: The code correctly checks if the OpenGL data buffers have been generated before attempting to generate them again. This is a good performance optimization to prevent unnecessary buffer generation.
shared/public/Tiled2dMapSourceImpl.h (4)
  • 364-380: The implementation of debouncing logic for new tile loading is a good practice to avoid unnecessary loading tasks when the visible tiles change rapidly. However, ensure that the PENDING_NEW_TILE_DEBOUNCE_MS constant is defined and has a reasonable value to balance responsiveness with performance.
Verification successful

The constant PENDING_NEW_TILE_DEBOUNCE_MS is defined in Tiled2dMapSource.h with a value of 200 milliseconds, which is a reasonable value for debouncing tile loading in a UI context.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that PENDING_NEW_TILE_DEBOUNCE_MS is defined and check its value.
rg --type cpp "PENDING_NEW_TILE_DEBOUNCE_MS"

Length of output: 307

* 389-398: The method `onStableTriggerNewTileLoading` is correctly checking if the update ID matches the current update ID before performing loading tasks. This ensures that only the latest update triggers the loading of new tiles, which is consistent with the debouncing logic. * 364-380: The use of a lambda function for debouncing tile loading is a good practice. However, it's important to ensure that the `LambdaTask` and `TaskConfig` are properly implemented and that the `scheduler` is capable of handling these tasks efficiently.
Verification successful
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the implementation of LambdaTask and TaskConfig, and ensure the scheduler can handle these tasks.
rg --type cpp "LambdaTask|TaskConfig"

Length of output: 12176



Script:

#!/bin/bash
# Verify the implementation details of the scheduler, specifically ThreadPoolSchedulerImpl
rg --type cpp "ThreadPoolSchedulerImpl"

Length of output: 2671



Script:

#!/bin/bash
# Verify the implementation details of the methods provided by ThreadPoolSchedulerImpl to understand task management
rg --type cpp -A 10 "void ThreadPoolSchedulerImpl::addTask" "shared/src/map/scheduling/ThreadPoolSchedulerImpl.cpp"

Length of output: 1597

* 364-380: The locking of `mailbox->receivingMutex` before sorting and potentially updating `pendingTilesToLoad` is a good practice to prevent data races in a multithreaded environment.

Comment on lines +657 to +658
auto result = value->evaluateOr(context, defaultValue);
return result;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ValueEvaluator class has been modified to assign the result of value->evaluateOr(context, defaultValue) to a local variable result before returning it. This change is redundant as the result is not used for any processing and is immediately returned. This adds unnecessary lines of code and may slightly impact performance due to the additional variable assignment.

- auto result = value->evaluateOr(context, defaultValue);
- return result;
+ return value->evaluateOr(context, defaultValue);

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
auto result = value->evaluateOr(context, defaultValue);
return result;
return value->evaluateOr(context, defaultValue);

@@ -164,8 +164,9 @@ class Tiled2dMapSource :
void onVisibleTilesChanged(const std::vector<VisibleTilesLayer> &pyramid, int keepZoomLevelOffset = 0);

private:
void performLoadingTask(Tiled2dMapTileInfo tile, size_t loaderIndex);
void onStableTriggerNewTileLoading(uint64_t updateId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method onStableTriggerNewTileLoading has been added but lacks documentation.

Please add documentation to explain the purpose and usage of this method.

@@ -181,11 +182,14 @@

std::unordered_map<size_t, std::map<Tiled2dMapTileInfo, ErrorInfo>> errorTiles;
std::optional<long long> nextDelayTaskExecution;
std::vector<PrioritizedTiled2dMapTileInfo> pendingTilesToLoad;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The member pendingTilesToLoad has been added but lacks documentation.

Please add documentation to explain the purpose and usage of this member.


std::unordered_set<Tiled2dMapTileInfo> notFoundTiles;

std::string layerName;

uint64_t currentNewTilesUpdateId = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The member currentNewTilesUpdateId has been added but lacks documentation.

Please add documentation to explain the purpose and usage of this member.


std::unordered_set<Tiled2dMapTileInfo> notFoundTiles;

std::string layerName;

uint64_t currentNewTilesUpdateId = 0;
const static int64_t PENDING_NEW_TILE_DEBOUNCE_MS = 200;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constant PENDING_NEW_TILE_DEBOUNCE_MS has been added but lacks documentation.

Please add documentation to explain the purpose and usage of this constant.

Comment on lines +61 to +62
void removeFromCache();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate removeFromCache method definition.

- void removeFromCache();

Remove the duplicate method definition to prevent compilation errors.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
void removeFromCache();

@@ -127,6 +127,7 @@ class GLThread constructor(
hasFinishedSinceDirty = true
finishDuration = System.currentTimeMillis() - finishDuration
}
val finishDuration = System.currentTimeMillis() - preFinish
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable finishDuration is redeclared, which will cause a compilation error in Kotlin.

- val finishDuration = System.currentTimeMillis() - preFinish

Remove the redeclaration of finishDuration to use the previously declared variable.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
val finishDuration = System.currentTimeMillis() - preFinish

Comment on lines +106 to +112
if (!glDataBuffersGenerated) {
glGenBuffers(1, &positionsBuffer);
glGenBuffers(1, &textureCoordinatesListBuffer);
glGenBuffers(1, &scalesBuffer);
glGenBuffers(1, &rotationsBuffer);
glGenBuffers(1, &alphasBuffer);
glGenBuffers(1, &stretchInfoBuffer);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conditional block for generating OpenGL buffers only if they haven't been generated before is a good practice to avoid redundant operations. However, there is no corresponding flag set to true for glDataBuffersGenerated after the buffers are generated. This could lead to the buffers not being generated at all if glDataBuffersGenerated is not properly initialized to false.

if (!glDataBuffersGenerated) {
    glGenBuffers(1, &positionsBuffer);
    glGenBuffers(1, &textureCoordinatesListBuffer);
    glGenBuffers(1, &scalesBuffer);
    glGenBuffers(1, &rotationsBuffer);
    glGenBuffers(1, &alphasBuffer);
    glGenBuffers(1, &stretchInfoBuffer);
    glDataBuffersGenerated = true; // This line is missing to indicate that the buffers have been generated.
}

@maerki maerki deleted the bugfix/merged-optimizations branch February 16, 2024 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants