CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-lilconfig

A zero-dependency alternative to cosmiconfig for loading configuration files

89

1.21x
Overview
Eval results
Files

task.mdevals/scenario-3/

Configuration Cache Performance Monitor

Overview

Build a configuration loading system that measures and optimizes the performance of loading configuration files using caching. The system should be able to load configuration files multiple times, measure the performance difference with and without caching, and provide cache management capabilities.

Dependencies { .dependencies }

lilconfig { .dependency }

Provides configuration file search and loading capabilities with caching support.

Requirements

1. Configuration Loader Module

Create a module that provides configuration loading functionality with performance tracking:

  • Initialize a configuration loader for a specific configuration name (e.g., "myapp")
  • Load configuration files by absolute filepath
  • Track loading performance metrics (time taken in milliseconds)
  • Expose cache management operations
  • Demonstrate both cached and uncached loading behavior

2. Performance Comparison

Implement functionality to measure performance differences:

  • Perform an initial load of a configuration file and record the time taken
  • Perform subsequent loads of the same configuration file
  • Measure and compare load times between initial and cached loads
  • Calculate and report the performance improvement ratio

3. Cache Management

Provide cache control operations:

  • Clear the load cache explicitly
  • Verify that cache clearing affects subsequent loads
  • Demonstrate that loads after cache clearing behave like initial loads

4. Implementation Files

Create the following files:

  • config-loader.js - Main module implementing the configuration loader with caching
  • config-loader.test.js - Test file demonstrating the caching behavior

Test Cases

Test Case 1: Cached Load Performance @test

Description: Loading the same configuration file multiple times should show significant performance improvement due to caching.

Steps:

  1. Create a test configuration file (e.g., test.config.json)
  2. Load the configuration file for the first time and record the duration
  3. Load the same configuration file a second time and record the duration
  4. The second load should be faster than the first load
  5. The configuration content should be identical for both loads

Expected Result: The cached load (second load) should be noticeably faster than the initial load, demonstrating the caching optimization.

Test Case 2: Cache Clearing @test

Description: Clearing the cache should cause subsequent loads to perform like initial loads.

Steps:

  1. Load a configuration file (initial load)
  2. Load the same file again (cached load - should be fast)
  3. Clear the load cache
  4. Load the same file again (should perform like an initial load)

Expected Result: After clearing the cache, the load time should be similar to the initial load time, confirming that the cache was successfully cleared.

Test Case 3: Multiple Files Cached Independently @test

Description: Different configuration files should be cached independently.

Steps:

  1. Load configuration file A
  2. Load configuration file B
  3. Load configuration file A again (should use cache)
  4. Load configuration file B again (should use cache)
  5. Clear the cache
  6. Both files should show uncached behavior on next load

Expected Result: Each file maintains its own cache entry, and clearing the cache affects all cached files.

Notes

  • Use high-resolution timing (e.g., performance.now()) for accurate performance measurements
  • Configuration files can be simple JSON files for testing purposes
  • The performance improvement from caching should be measurable and consistent
  • Consider file system I/O as the primary bottleneck that caching addresses

Install with Tessl CLI

npx tessl i tessl/npm-lilconfig

tile.json