Skip to content

Performance & Serialization Enhancements#20

Merged
afshawnlotfi merged 22 commits intomainfrom
improve-perf-2
Mar 9, 2026
Merged

Performance & Serialization Enhancements#20
afshawnlotfi merged 22 commits intomainfrom
improve-perf-2

Conversation

@afshawnlotfi
Copy link
Copy Markdown
Member

@afshawnlotfi afshawnlotfi commented Mar 9, 2026

Overview

This PR introduces significant performance optimizations, improved serialization capabilities, and enhanced caching mechanisms for the Meshly library across both Python and TypeScript implementations.

Key Changes

🚀 Performance Optimizations

  • xxhash Integration: Replaced SHA256 with xxhash64 for faster checksum computation of binary data
  • orjson Serialization: Switched to orjson for faster JSON encoding/decoding in Packable serialization
  • Fork-based Parallelism: Added ForkPool utility for parallel processing on POSIX systems with copy-on-write memory sharing
  • uint8 Data Types: Refactored index sizes and cell types from uint32 to uint8 for optimized memory usage
  • Optimized Array Encoding: Streamlined array encoding/decoding in ArrayUtils

💾 Caching System

  • PackableCache: New two-tier LRU cache (in-memory + disk) for efficient Packable object caching
  • Batch Operations: Support for get_many() and put_many() with parallelized disk I/O via ForkPool

🔧 Serialization Enhancements

  • _ListAnnotation: Added support for inline JSON list serialization
  • Checksum Support: Enhanced Packable and SerializationUtils with content checksums for deduplication
  • Deterministic Gzip: Added deterministic gzip compression for reproducible outputs
  • Pickle Support: Added helper function for pickle serialization of Packable objects

🏭 API Improvements

  • Factory Methods: Refactored mesh creation to use create() factory methods for consistent instantiation
  • Markers Parameter: Updated to accept Nx3 numpy arrays for enhanced flexibility
  • Dynamic Model Resolution: Enhanced SchemaUtils with nested model reconstruction and discriminator matching

🌐 Web Worker Support (TypeScript)

  • PackableWorker: New web worker for offloading Packable reconstruction to background threads
  • Worker Entry Point: Added meshly/worker module for easy worker instantiation
  • Message Types: Defined typed message interfaces for reconstruct, decode, and decodeArray operations

📁 Storage Refactoring

  • Unified Root Directory: Refactored PackableStore to use a unified root directory structure
  • Dynamic Extracted Directory: Removed EXTRACTED_DIR constant in favor of dynamic path resolution

🐛 Bug Fixes

  • Asset Handling: Improved resource and array type checks in SchemaUtils
  • Type Annotations: Refactored extract_value to use extract_basemodel for better type preservation

Files Changed

  • 42 files modified
  • +2,733 / -1,060 lines changed

Breaking Changes

  • Mesh classes now require create() factory method instead of direct instantiation
  • Index sizes and cell types changed from uint32 to uint8
  • Constants renamed for unified directory structure

Dependencies

  • Added: xxhash, orjson

- Changed data types for index sizes and cell types from uint32 to uint8 in various classes and functions to optimize memory usage.
- Updated the ElementUtils and ElementData classes to handle the new data types and added a method to create ElementData from polygons.
- Modified the Mesh class to accommodate the new data types and adjusted related methods for consistency.
- Updated tests to reflect changes in data types, ensuring compatibility with the new structure.
- Adjusted TypeScript interfaces to align with the changes in the Python implementation, including updates to JSON schema definitions.
- Updated all test files to replace direct instantiation of Mesh and its subclasses with the new factory method `create()`.
- Ensured that the conversion methods in tests now utilize the updated mesh creation approach.
- Adjusted tests for handling JAX arrays to align with the new instantiation method.
- Modified tests for dictionary arrays and dynamic models to reflect the changes in mesh creation.
- Ensured that all instances of `Mesh` and `CustomMesh` are created using the `create()` method for consistency and to leverage any internal optimizations.
@afshawnlotfi afshawnlotfi changed the title Improve perf 2 Performance & Serialization Enhancements Mar 9, 2026
@afshawnlotfi afshawnlotfi merged commit 9076c82 into main Mar 9, 2026
1 of 4 checks passed
afshawnlotfi added a commit that referenced this pull request Mar 10, 2026
* feat: Add _ListAnnotation for inline JSON list serialization and enhance SchemaUtils for list handling

* fix: Improve asset handling in SchemaUtils by refining resource and array type checks

* feat: Enhance pickle serialization support in Packable class with a helper function

* feat: Add PackableWorker and worker entry point for offloading Packable reconstruction

* feat: Refactor extract_value method to use extract_basemodel for improved type annotation preservation

* feat: Optimize array encoding and decoding in ArrayUtils; enhance Packable serialization with orjson and caching

* Refactor meshly to use uint8 for index sizes and cell types

- Changed data types for index sizes and cell types from uint32 to uint8 in various classes and functions to optimize memory usage.
- Updated the ElementUtils and ElementData classes to handle the new data types and added a method to create ElementData from polygons.
- Modified the Mesh class to accommodate the new data types and adjusted related methods for consistency.
- Updated tests to reflect changes in data types, ensuring compatibility with the new structure.
- Adjusted TypeScript interfaces to align with the changes in the Python implementation, including updates to JSON schema definitions.

* feat: Integrate xxhash for improved checksum computation and add deterministic gzip compression

* Refactor mesh creation to use factory methods

- Updated all test files to replace direct instantiation of Mesh and its subclasses with the new factory method `create()`.
- Ensured that the conversion methods in tests now utilize the updated mesh creation approach.
- Adjusted tests for handling JAX arrays to align with the new instantiation method.
- Modified tests for dictionary arrays and dynamic models to reflect the changes in mesh creation.
- Ensured that all instances of `Mesh` and `CustomMesh` are created using the `create()` method for consistency and to leverage any internal optimizations.

* feat: Enhance Packable and SerializationUtils with checksum support and optimized extraction

* feat: Enhance SchemaUtils with nested model reconstruction and dynamic model instantiation

* feat: Update markers parameter to accept Nx3 numpy arrays and enhance handling in mesh creation

* refactor: Rename constants and update PackableStore to use a unified root directory structure

* feat: Implement PackableCache for efficient in-memory and disk caching of Packable objects

* refactor: Remove EXTRACTED_DIR constant and update PackableStore to use dynamic extracted directory

* feat: Add discriminator matching support in SchemaUtils for enhanced model resolution

* feat: Enhance PackableStore with root and extracted directory structure; add PackableCache for improved caching; update tests and documentation

* refactor: Replace xxhash with SHA256 for checksum computation and remove xxhash dependency

* feat: Add InlineArray type for inline JSON serialization; update related documentation and utilities

* refactor: Update extract_checksums method to be static and accept data dict as parameter

* chore: Bump version to 3.2.0-alpha in pyproject.toml and package.json
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.

1 participant