Repository: alacritty/alacritty
File: alacritty/src/display/mod.rs (Rust)

Code before:
            event_loop,
            config,
            identity,
            estimated_size,
            #[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
            wayland_event_queue,
        )?;

        // Create renderer.
        let mut renderer = Renderer::new()?;

        let scale_factor = window.scale_factor;
        info!("Display scale factor: {}", scale_factor);

        // If the scaling factor changed update the glyph cache and mark for resize.
        let should_resize = (estimated_scale_factor - window.scale_factor).abs() > f64::EPSILON;
        let (cell_width, cell_height) = if should_resize {
            Self::update_font_size(&mut glyph_cache, scale_factor, config, font)
        } else {
            (cell_width, cell_height)
        };

        // Load font common glyphs to accelerate rendering.
        debug!("Filling glyph cache with common glyphs");
        renderer.with_loader(|mut api| {
            glyph_cache.clear_glyph_cache(&mut api);
        });

        if let Some(dimensions) = dimensions.filter(|_| should_resize) {
            // Resize the window again if the scale factor was not estimated correctly.
            let size =
                window_size(config, dimensions, cell_width, cell_height, window.scale_factor);
            window.set_inner_size(size);
        }

        let padding = config.window.padding(window.scale_factor);
        let viewport_size = window.inner_size();

        // Create new size with at least one column and row.
        let size_info = SizeInfo::new(
            viewport_size.width as f32,
            viewport_size.height as f32,
            cell_width,
            cell_height,
            padding.0,
            padding.1,
            config.window.dynamic_padding && dimensions.is_none(),
        );

        info!("Cell size: {} x {}", cell_width, cell_height);
        info!("Padding: {} x {}", size_info.padding_x(), size_info.padding_y());

Review comment (performance):
I feel like the `clear_glyph_cache` function has a pretty bad name. I actually had to look it up just to make sure it actually loads the common glyphs.

Maybe something like `reset_glpyh_cache` would be more appropriate? Just to indicate it is reset to a specific state, not emptied?

Code after:
        debug!("Estimated cell size: {} x {}", cell_width, cell_height);

        // Spawn the Alacritty window.
        let window = Window::new(
            event_loop,
            config,
            identity,
            estimated_size,
            #[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
            wayland_event_queue,
        )?;

        // Create renderer.
        let mut renderer = Renderer::new()?;

        let scale_factor = window.scale_factor;
        info!("Display scale factor: {}", scale_factor);

        // If the scaling factor changed update the glyph cache and mark for resize.
        let should_resize = (estimated_scale_factor - window.scale_factor).abs() > f64::EPSILON;
        let (cell_width, cell_height) = if should_resize {
            Self::update_font_size(&mut glyph_cache, scale_factor, config, font)
        } else {
            (cell_width, cell_height)
        };

        // Load font common glyphs to accelerate rendering.
        debug!("Filling glyph cache with common glyphs");
        renderer.with_loader(|mut api| {
            glyph_cache.reset_glyph_cache(&mut api);
        });

        if let Some(dimensions) = dimensions.filter(|_| should_resize) {
            // Resize the window again if the scale factor was not estimated correctly.
            let size =
                window_size(config, dimensions, cell_width, cell_height, window.scale_factor);
            window.set_inner_size(size);
        }

        let padding = config.window.padding(window.scale_factor);
        let viewport_size = window.inner_size();

        // Create new size with at least one column and row.
        let size_info = SizeInfo::new(
            viewport_size.width as f32,
            viewport_size.height as f32,
            cell_width,
            cell_height,
            padding.0,
            padding.1,
            config.window.dynamic_padding && dimensions.is_none(),