Skip to content

Daily Perf Improver: Research and Plan #1534

Description

@github-actions

Daily Perf Improver: Research and Plan

Performance Testing Infrastructure

Current Testing Setup

  • Build System: FAKE-based build using build/build.fs with .NET 8.0
  • Test Framework: NUnit with FsUnit for tests, GitHubActionsTestLogger for CI
  • CI/CD: GitHub Actions on Windows and Ubuntu (pull-requests.yml, push-master.yml)
  • Build Commands:
    • build.sh -t Build / build.cmd -t Build
    • dotnet run --project build/build.fsproj -- -t RunTests
    • dotnet run --project build/build.fsproj -- -t All

Available Tools for Performance Work

  • Formatting: Fantomas for code formatting
  • Documentation: FsDocs for documentation generation
  • No BenchmarkDotNet: Currently no micro-benchmarking framework detected
  • Basic Performance Measurement: Some Stopwatch usage found in tests (HtmlParser.fs, IO.fs)

FSharp.Data Architecture and Performance-Critical Areas

Core Components

  1. JSON Processing (FSharp.Data.Json.Core/)

    • JsonValue.fs: Core JSON representation and parsing
    • JsonConversions.fs: Type conversions
    • JsonInference.fs: Type inference engine
    • JsonRuntime.fs: Runtime operations
  2. CSV Processing (FSharp.Data.Csv.Core/)

    • CsvFile.fs: Core CSV file handling
    • CsvInference.fs: Type inference
    • CsvRuntime.fs: Runtime operations
  3. HTML Processing (FSharp.Data.Html.Core/)

    • HtmlParser.fs: HTML parsing engine
    • HtmlCssSelectors.fs: CSS selector engine
    • HtmlCharRefs.fs: Character reference handling
  4. XML Processing (FSharp.Data.Xml.Core/)

    • XmlInference.fs: XML type inference
    • XsdInference.fs: XSD schema inference
  5. Common Runtime (FSharp.Data.Runtime.Utilities/)

    • StructuralInference.fs: Core type inference algorithms
    • TextConversions.fs: Text parsing and conversion utilities
    • IO.fs: File and URI resolution with caching
    • Caching.fs: Caching mechanisms
  6. HTTP (FSharp.Data.Http/)

    • Http.fs: HTTP client functionality
  7. Design-Time Components (FSharp.Data.DesignTime/)

    • Type provider implementations for all formats

Historical Performance Improvements

From release notes analysis, significant performance work has been done:

  • JSON: 20% parsing performance improvement (v2.3.0-beta2), improved JsonValue.Parse() and ToString() performance
  • HTML: Improved CDATA parsing performance (v3.0.0-beta3)
  • CSV: Support for large CSV files, streaming mode implementation
  • General: Multiple "performance improvements" mentioned across versions
  • Memory: Type provider design time component memory leak fixes and performance improvements
  • Number Parsing: Improved performance of number and DateTime parsing

Typical Workloads and Bottlenecks

Primary Use Cases:

  1. Type Provider Design-Time: Schema inference from sample data (JSON, XML, CSV, HTML)
  2. Runtime Data Processing: Parsing and processing data files
  3. HTTP Data Access: Fetching and processing remote data sources
  4. Large File Handling: Processing big CSV files, large JSON documents

Likely Performance Bottlenecks:

  1. Type Inference: Complex structural inference algorithms in StructuralInference.fs
  2. String Processing: Heavy text parsing and conversion operations
  3. Memory Allocation: Creating intermediate objects during parsing
  4. I/O Operations: File reading and HTTP requests
  5. Reflection: Type provider code generation and runtime operations

Performance Goals and Priorities

Round 1 (Low-hanging fruit):

  • Add BenchmarkDotNet for micro-benchmarking infrastructure
  • Profile and optimize JSON parsing hot paths
  • Improve string allocation patterns in parsers
  • Optimize common type conversion operations

Round 2 (Medium complexity):

  • Optimize structural inference algorithms
  • Improve CSV streaming performance for large files
  • Enhance HTML parser efficiency
  • Reduce memory allocations in type providers

Round 3 (Advanced):

  • Implement vectorization for numeric parsing where applicable
  • Optimize HTTP client performance
  • Improve caching mechanisms
  • Advanced parser optimizations (JSON, XML, HTML)

Measurement Strategy

Current Constraints:

  • No dedicated performance testing infrastructure
  • Tests run in virtualized GitHub Actions environment (timing may vary)
  • Need to establish baseline measurements

Proposed Approach:

  1. Add BenchmarkDotNet to test dependencies
  2. Create performance test suite covering key scenarios:
    • JSON parsing of various document sizes
    • CSV processing of large files
    • HTML parsing of complex documents
    • Type inference on representative samples
  3. Focus on relative improvements rather than absolute timing
  4. Use memory profiling to identify allocation hot spots

Environment Setup Steps

Prerequisites:

  • .NET 8.0 SDK (specified in global.json)
  • Restore tools: dotnet tool restore
  • Restore packages: dotnet paket restore

Performance Development Workflow:

  1. Build: dotnet run --project build/build.fsproj -- -t Build
  2. Run tests: dotnet run --project build/build.fsproj -- -t RunTests
  3. Format code: dotnet run --project build/build.fsproj -- -t Format
  4. [Need to add] Run benchmarks: TBD after BenchmarkDotNet integration

Repository Maintainer Focus Areas

Based on historical release notes, maintainers prioritize:

  • Correctness: Maintaining spec compliance (JSON, CSV standards)
  • Memory Management: Preventing leaks in type providers
  • Large File Support: Streaming and efficient processing
  • API Stability: Maintaining backward compatibility
  • Cross-platform: Windows/Linux support

Next Steps

  1. Set up BenchmarkDotNet infrastructure for reliable micro-benchmarking
  2. Profile existing hot paths using sample data
  3. Create baseline performance measurements
  4. Identify specific optimization targets based on profiling results
  5. Implement targeted optimizations with before/after measurements

Testing Commands

# Build and test
dotnet run --project build/build.fsproj -- -t All

# Run tests only  
dotnet run --project build/build.fsproj -- -t RunTests

# Format code
dotnet run --project build/build.fsproj -- -t Format

# Check formatting
dotnet run --project build/build.fsproj -- -t CheckFormat

AI-generated content by Daily Perf Improver may contain mistakes.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions