Reuse verified default font maps and streamline capacity scans
This commit is contained in:
1 parent
7707cd9b09
commit
d9143ddbd1
5 files changed
+137
-38
No files matched your search
@@ -1389,20 +1389,27 @@ impl Default for State {
|
||||
impl State {
|
||||
pub(super) fn collect_statistics(&self, c: &mut super::statistics::Collector) {
|
||||
use super::statistics::Ownership::Active;
|
||||
for b in self.boxes.values() {
|
||||
c.native_box(b, Active);
|
||||
}
|
||||
if c.material_only() {
|
||||
for saved in self.groups.iter().flat_map(|group| group.saved.values()) {
|
||||
if let Saved::Box(Some(b)) = saved {
|
||||
c.native_box(b, Active);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
c.usage.state.command_entries = self.commands.len();
|
||||
c.usage.state.control_name_bytes = self
|
||||
.commands
|
||||
.keys()
|
||||
.map(|n| match n {
|
||||
CommandName::Control(n) => n.len(),
|
||||
_ => 0,
|
||||
})
|
||||
.sum();
|
||||
c.usage.state.macro_bindings = self
|
||||
.commands
|
||||
.values()
|
||||
.filter(|m| matches!(m, Meaning::Macro(_)))
|
||||
.count();
|
||||
for (name, meaning) in &self.commands {
|
||||
if let CommandName::Control(name) = name {
|
||||
c.usage.state.control_name_bytes += name.len();
|
||||
}
|
||||
if let Meaning::Macro(macro_definition) = meaning {
|
||||
c.usage.state.macro_bindings += 1;
|
||||
c.macro_body(macro_definition);
|
||||
}
|
||||
}
|
||||
c.usage.state.token_registers = self.toks.len() + self.xe_inter_char_tokens.len();
|
||||
c.usage.state.parameter_entries =
|
||||
self.parameters.len() + self.token_parameters.len() + self.job_parameters.len();
|
||||
@@ -1428,20 +1435,12 @@ impl State {
|
||||
c.usage.state.hyphenation_trie_nodes = nodes;
|
||||
c.usage.state.hyphenation_edges = edges;
|
||||
c.usage.state.pattern_weight_cells = weights;
|
||||
for m in self.commands.values() {
|
||||
if let Meaning::Macro(m) = m {
|
||||
c.macro_body(m);
|
||||
}
|
||||
}
|
||||
for v in self.toks.values() {
|
||||
c.usage.token_list_cells += v.len();
|
||||
}
|
||||
for v in self.token_parameters.values().chain(self.xe_inter_char_tokens.values()) {
|
||||
c.shared_tokens(v);
|
||||
}
|
||||
for b in self.boxes.values() {
|
||||
c.native_box(b, Active);
|
||||
}
|
||||
for m in self.split_marks.values() {
|
||||
c.shared_tokens(&m.first);
|
||||
c.shared_tokens(&m.bottom);
|
||||
|
||||
@@ -162,6 +162,10 @@ impl Collector {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn material_only(&self) -> bool {
|
||||
self.shared_lists.is_some()
|
||||
}
|
||||
|
||||
pub fn macro_body(&mut self, m: &Arc<Macro>) {
|
||||
if self.macros.insert(Arc::as_ptr(m) as usize) {
|
||||
self.usage.unique_macro_bodies += 1;
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::{
|
||||
use std::{
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
@@ -301,6 +301,18 @@ enum MapMode {
|
||||
Delete,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
struct MapTables {
|
||||
entries: Arc<BTreeMap<String, Arc<MapEntry>>>,
|
||||
// PDF inclusion addresses the PostScript name independently of the TFM.
|
||||
postscript: Arc<BTreeMap<PostscriptKey, (String, Arc<MapEntry>)>>,
|
||||
}
|
||||
|
||||
// Keep one bounded, verified default map across jobs. Its tables contain
|
||||
// pure map entries, while a job's font bindings and used names stay local.
|
||||
const MAX_CACHED_DEFAULT_MAP_BYTES: usize = 512 * 1024;
|
||||
static DEFAULT_MAP: Mutex<Option<(ResourceVersion, MapTables)>> = Mutex::new(None);
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub(super) struct JobFontMap {
|
||||
// Ordinary unevaluated pages can retain raw lists for hosts that only
|
||||
@@ -309,11 +321,9 @@ pub(super) struct JobFontMap {
|
||||
first_font_source: Option<PathBuf>,
|
||||
pending_fonts: Vec<(FontId, String)>,
|
||||
pending_ids: BTreeSet<FontId>,
|
||||
entries: Arc<BTreeMap<String, Arc<MapEntry>>>,
|
||||
tables: MapTables,
|
||||
subfonts: sfd::Files,
|
||||
used_names: BTreeSet<String>,
|
||||
// PDF inclusion addresses the PostScript name independently of the TFM.
|
||||
postscript_entries: Arc<BTreeMap<PostscriptKey, (String, Arc<MapEntry>)>>,
|
||||
used_postscript: BTreeSet<PostscriptKey>,
|
||||
bindings: Option<Arc<PdfFontBindings>>,
|
||||
}
|
||||
@@ -361,11 +371,11 @@ impl JobFontMap {
|
||||
if bindings.fonts.contains_key(&id) {
|
||||
return;
|
||||
}
|
||||
let entry = self.entries.get(name).cloned();
|
||||
let entry = self.tables.entries.get(name).cloned();
|
||||
if let Some(entry) = &entry {
|
||||
self.used_names.insert(name.into());
|
||||
if let Some(key) = entry.postscript_key()
|
||||
&& self.postscript_entries.get(&key).is_some_and(|(_, imported)| Arc::ptr_eq(imported, entry))
|
||||
&& self.tables.postscript.get(&key).is_some_and(|(_, imported)| Arc::ptr_eq(imported, entry))
|
||||
{
|
||||
self.used_postscript.insert(key);
|
||||
}
|
||||
@@ -383,8 +393,7 @@ impl JobFontMap {
|
||||
if default_pending || self.first_font_source.is_some() {
|
||||
let from = self.first_font_source.as_deref().unwrap_or(from);
|
||||
if let Some(read) = load_map(files, "pdftex.map", from)? {
|
||||
let mut ignored = Vec::new();
|
||||
self.apply_file(&read, MapMode::Add, true, &mut ignored, files)?;
|
||||
self.apply_default_map(&read, files)?;
|
||||
bindings.default_map = Some(read.version);
|
||||
}
|
||||
}
|
||||
@@ -396,6 +405,33 @@ impl JobFontMap {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn apply_default_map(
|
||||
&mut self,
|
||||
read: &LoadedResource,
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<(), String> {
|
||||
let cacheable = read.data.len() <= MAX_CACHED_DEFAULT_MAP_BYTES
|
||||
// SFD templates need the current job's resource provider.
|
||||
&& !read.data.contains(&b'@')
|
||||
&& self.tables.entries.is_empty()
|
||||
&& self.tables.postscript.is_empty();
|
||||
if cacheable {
|
||||
let cached = DEFAULT_MAP.lock().expect("native default map cache poisoned");
|
||||
if let Some((version, tables)) = cached.as_ref()
|
||||
&& *version == read.version
|
||||
{
|
||||
self.tables = tables.clone();
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
self.apply_file(read, MapMode::Add, true, &mut Vec::new(), files)?;
|
||||
if cacheable {
|
||||
*DEFAULT_MAP.lock().expect("native default map cache poisoned") =
|
||||
Some((read.version.clone(), self.tables.clone()));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn imported_type1_program(
|
||||
&mut self, name: &str, from: &Path, files: &mut impl SourceProvider,
|
||||
) -> Result<Option<MappedType1>, String> {
|
||||
@@ -404,7 +440,7 @@ impl JobFontMap {
|
||||
self.initialize(true, from, files)?;
|
||||
}
|
||||
let key = (name.to_owned(), transform.slant, transform.extend);
|
||||
let Some((tfm, entry)) = self.postscript_entries.get(&key) else { return Ok(None) };
|
||||
let Some((tfm, entry)) = self.tables.postscript.get(&key) else { return Ok(None) };
|
||||
let file = entry.type1_file(name)?;
|
||||
let Some(resource) = files.optional_font_file(ResourceKind::Type1, file,
|
||||
&entry.from.to_string_lossy())? else { return Ok(None) };
|
||||
@@ -412,7 +448,7 @@ impl JobFontMap {
|
||||
let mut font = crate::type1::Type1Font::from_file(&resource.data)
|
||||
.map_err(|error| format!("{error}: {}", resource.version.path.display()))?;
|
||||
font.apply_map_transform(transform)?;
|
||||
if self.entries.get(tfm).is_some_and(|direct| Arc::ptr_eq(direct, entry)) {
|
||||
if self.tables.entries.get(tfm).is_some_and(|direct| Arc::ptr_eq(direct, entry)) {
|
||||
self.used_names.insert(tfm.clone());
|
||||
}
|
||||
self.used_postscript.insert(key);
|
||||
@@ -533,7 +569,7 @@ impl JobFontMap {
|
||||
suppress_duplicates: bool,
|
||||
warnings: &mut Vec<String>,
|
||||
) {
|
||||
if self.entries.contains_key(&name) {
|
||||
if self.tables.entries.contains_key(&name) {
|
||||
if mode == MapMode::Add {
|
||||
if !suppress_duplicates {
|
||||
warnings.push(format!(
|
||||
@@ -551,19 +587,19 @@ impl JobFontMap {
|
||||
}
|
||||
let entry = Arc::new(entry);
|
||||
if mode == MapMode::Delete {
|
||||
Arc::make_mut(&mut self.entries).remove(&name);
|
||||
Arc::make_mut(&mut self.tables.entries).remove(&name);
|
||||
} else {
|
||||
Arc::make_mut(&mut self.entries).insert(name.clone(), entry.clone());
|
||||
Arc::make_mut(&mut self.tables.entries).insert(name.clone(), entry.clone());
|
||||
}
|
||||
let Some(key) = entry.postscript_key() else { return };
|
||||
if self.postscript_entries.contains_key(&key) {
|
||||
if self.tables.postscript.contains_key(&key) {
|
||||
if mode == MapMode::Add || self.used_postscript.contains(&key) {
|
||||
return;
|
||||
}
|
||||
Arc::make_mut(&mut self.postscript_entries).remove(&key);
|
||||
Arc::make_mut(&mut self.tables.postscript).remove(&key);
|
||||
}
|
||||
if mode != MapMode::Delete && entry.type1_file(&name).is_ok() {
|
||||
Arc::make_mut(&mut self.postscript_entries).insert(key, (name, entry));
|
||||
Arc::make_mut(&mut self.tables.postscript).insert(key, (name, entry));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,51 @@
|
||||
| W6 会话 | 实施中 | 共享库/CLI 与当前原生文字/数学/规则来源进入公共结果;真实 A4 副本九类/27 revision 与独立干净作业页面/PDF/aux/映射一致,新增数学场景独立参考通过;详细失败/捕获重放及宿主/离线/CLI观察已通过;原子项目版本/已知生成初态及TeX流记录已接通;完整副作用/恢复契约、旧来源和性能仍缺 |
|
||||
| W7 总验收 | 未满足 | 原有和新增测试、原样项目、格式与会话门禁全部通过才能结项 |
|
||||
|
||||
## 2026-11-28 A4 热编辑的字体映射与容量检查
|
||||
|
||||
用主线 7707cd9 的优化库接入同版编辑器,加载真实 schema104
|
||||
LaTeX 格式。12 次 A4 主文件热编辑的定向阶段记录显示约 5.6 万步
|
||||
重执行,执行时间最大。追加 8 次实际编辑的 259 个 CPU 样本中,
|
||||
13 个落在字体映射解析和应用,10 个落在状态资源统计。原样
|
||||
main.tex、chapter.tex、环境、时钟和基线保留。
|
||||
|
||||
跨作业共享已验证的默认字体映射表。每次仍按当前作业读取并验证
|
||||
映射资源,复用键为实际路径、长度和内容指纹。只有同版本、至多
|
||||
512 KiB 且无 SFD 引用的表进入单项缓存。已使用名称、字体绑定、
|
||||
SFD 读取及后续映射命令仍按当前作业执行,覆盖操作用写时复制。
|
||||
容量检查只遍历实际盒和保存的盒列表。完整诊断沿用全部统计项,
|
||||
合并命令绑定的三次扫描。
|
||||
|
||||
Edge 在同机交替测量,基线和候选各有 30 次主文件、30 次子文件
|
||||
编辑。每次等待实际 SVG 绘制和出版,再比较同一版本的 PDF、SVG、
|
||||
来源映射、执行步数和复用步数。逐次结果和最终 aux 相同。
|
||||
|
||||
| A4 编辑 | 基线可见 p50 / p95 (ms) | 候选可见 p50 / p95 (ms) | 配对中位数变化 (ms) |
|
||||
| --- | ---: | ---: | ---: |
|
||||
| 主文件 | 1429.2 / 3023.7 | 1032.4 / 2228.7 | -230.4 |
|
||||
| 子文件 | 1198.4 / 2554.2 | 1275.7 / 2471.2 | +21.9 |
|
||||
|
||||
主文件执行阶段的配对中位数缩短 131.8 ms。峰值 RSS 为
|
||||
353484 → 353440 KiB。该次绝对时延远高于历史 A4 测量,比较
|
||||
范围限本轮配对。两种场景都未到 100 ms。最终缓冲区在同一候选
|
||||
另启独立会话,零复用步数,PDF、SVG、来源映射和 aux 均相同。
|
||||
|
||||
发布构建和七项统计专项通过。字体的五项专项通过,包括真实
|
||||
默认映射变更后使旧检查点失效,输出改变且与独立全量一致。
|
||||
字体套件既有 Type 1 子集名断言在准确基线亦失败。容量套件
|
||||
的共享盒断言仍保留,归档核心与候选接受同一 40 节点共享盒,
|
||||
并均拒绝独立超限盒、带保留页超限及组内保存盒超限。所有失败
|
||||
保持原断言和日志。
|
||||
|
||||
回执在 target/p4-a4-hot-path-batch。receipt.json 的 SHA-256 为
|
||||
95f7ce10e4605a267ce07062f497f9472514d97ba8f0c412043c50e6b7393bfe。
|
||||
浏览器与独立全量回执分别为
|
||||
73a7e9d3752a15b7837ef7eb48afe79004cf0eec2a045af2f6ee1a2113565ae3 和
|
||||
8b228e5dcdcc372aed2270956ea1ca6c49eb0b69708d896a7a6048e41fe1d242。
|
||||
|
||||
下一批继续分解检查点拷贝、后缀执行和结束时状态比较,先减少
|
||||
可证明的重复工作。固定预算、完整兼容性和分规模验收保持。
|
||||
|
||||
## 2026-11-28 活动页面的插入高度和原样项目核查
|
||||
|
||||
pdfTeX 模式的可展开 \pdfinsertht 直接读取页构建中实际插入类
|
||||
|
||||
@@ -591,7 +591,8 @@ fn shared_pdf_font_object_survives_a_checkpoint_and_size_edit() {
|
||||
request.etex = true;
|
||||
let compiler = NativeCompiler::default().with_entry_checkpoints(prefix.len() + 60);
|
||||
let first = compiler.compile(request.clone().with_project(snapshot.clone())).unwrap();
|
||||
let revised = request.with_project(snapshot.with_file_edits(2, [(later, body(12))].into()).unwrap());
|
||||
let edited = snapshot.with_file_edits(2, [(later, body(12))].into()).unwrap();
|
||||
let revised = request.clone().with_project(edited.clone());
|
||||
let next = compiler.compile(revised.clone()).unwrap();
|
||||
assert!(next.entry_checkpoint_work.reused_steps > 0);
|
||||
let delta = next.preview_since(Some(first.revision())).unwrap();
|
||||
@@ -611,5 +612,19 @@ fn shared_pdf_font_object_survives_a_checkpoint_and_size_edit() {
|
||||
assert_eq!(fonts.len(), 2);
|
||||
assert!(fonts.iter().all(|(_, object)| object.as_reference().unwrap() == shared));
|
||||
assert_eq!(pdf.get_dictionary(shared).unwrap().get(b"Subtype").unwrap().as_name().unwrap(), b"Type1");
|
||||
|
||||
// The resolved default tables refer to the bytes read in this revision.
|
||||
let changed_map = Arc::from(b"cmr10 CMR10 \"0.12 SlantFont\" <cmr10.pfb\n".as_slice());
|
||||
let project = edited
|
||||
.with_file_edits(3, [(root.join("pdftex.map"), changed_map)].into())
|
||||
.unwrap();
|
||||
let revised = request.with_project(project);
|
||||
let remapped = compiler.compile(revised.clone()).unwrap();
|
||||
assert_eq!(remapped.entry_checkpoint_work.reused_steps, 0);
|
||||
assert_ne!(remapped.pdf, next.pdf);
|
||||
let full = NativeCompiler::default().compile(revised).unwrap();
|
||||
assert_eq!(remapped.pdf, full.pdf);
|
||||
assert_eq!(remapped.source_map.pages, full.source_map.pages);
|
||||
assert_eq!(remapped.preview_since(None).unwrap().pages, full.preview_since(None).unwrap().pages);
|
||||
fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
Reference in new issue
Block a user