Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## 2024-06-07 - Avoid format! for single integer to string conversions

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Typo: Incorrect year in date.

The date shows "2024-06-07" but the PR was created on "2026-06-07". Please correct the year to 2026.

📝 Proposed fix
-## 2024-06-07 - Avoid format! for single integer to string conversions
+## 2026-06-07 - Avoid format! for single integer to string conversions
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
## 2024-06-07 - Avoid format! for single integer to string conversions
## 2026-06-07 - Avoid format! for single integer to string conversions
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.jules/bolt.md at line 1, Update the header line "## 2024-06-07 - Avoid
format! for single integer to string conversions" to use the correct year 2026
(i.e., "## 2026-06-07 - Avoid format! for single integer to string conversions")
so the date matches the PR creation date; locate and edit that exact header
string in .jules/bolt.md.

**Learning:** `format!("{var}")` invokes `alloc::format!` which requires parsing the format string and comes with formatting overhead. For simply converting an integer to a string, calling `var.to_string()` (from `alloc::string::ToString` trait) is significantly faster in `#![no_std]` as it relies on optimized itoa under the hood and exactly allocates the capacity.
**Action:** Replace `format!("{}", fd)` with `alloc::string::ToString::to_string(&fd)` (or just import the trait) to avoid runtime format string parsing and potential over-allocations when converting single integers to strings in `procfs.rs`.
Comment on lines +2 to +3
## 2024-06-07 - Avoid vec![0; N] when the buffer is immediately overwritten
**Learning:** Initializing large buffers with `vec![0; N]` in `#![no_std]` allocates and zeroes out the memory. For buffers like block device reads (`raw` array in `ext4`) that are immediately overwritten by a `read_block` system call, this zeroing is unnecessary overhead. However, safe Rust requires `read_block` to write to a valid initialized buffer (or an `&mut [u8]`). Using `vec![0; N]` is often fine for small arrays, but can be a bottleneck for large ones. In Ext4 write/read block functions, there are allocations for `vec![0u8; self.sector_size]` which is 512 bytes or 4KB, where zero initialization happens every time. Given safe Rust limitations without `MaybeUninit`, keeping `vec![0; ...]` might be necessary, but we can potentially optimize buffer usage or caching. Another optimization is `String::to_string` instead of `format!`.
**Action:** Replace `format!("{}", fd)` with `fd.to_string()` in procfs iteration as it is an easy and significant performance improvement within hot loop.
12 changes: 6 additions & 6 deletions arceos/modules/axfs/src/fs/procfs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloc::{borrow::ToOwned, collections::BTreeMap, format, string::String, sync::Arc, vec::Vec};
use alloc::{borrow::ToOwned, collections::BTreeMap, format, string::{String, ToString}, sync::Arc, vec::Vec};
use core::{
any::Any,
borrow::Borrow,
Expand Down Expand Up @@ -531,7 +531,7 @@ impl ProcFilesystem {

if let Some(fds) = provider.process_fds(pid) {
for fd in fds {
let name = format!("{}", fd);
let name = fd.to_string(); // Bolt: Use to_string() instead of format! for single integer conversion to avoid allocation overhead

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This inline comment is redundant and adds unnecessary noise to the codebase. The use of to_string() is idiomatic and self-explanatory, so the comment can be safely removed.

Suggested change
let name = fd.to_string(); // Bolt: Use to_string() instead of format! for single integer conversion to avoid allocation overhead
let name = fd.to_string();

let child_ino = PID_INODE_START + (pid << PID_INODE_SHIFT) + SUB_INO_FD_BASE + fd as u64;
entries.insert(name.into(), InodeRef::new(child_ino));
}
Expand Down Expand Up @@ -706,7 +706,7 @@ fn render_proc_file(fs: &ProcFilesystem, kind: ProcLiveFileKind) -> String {
ProcLiveFileKind::SelfSymlink => {
if let Some(provider) = PROCESS_PROVIDER.get() {
if let Some(pid) = provider.current_pid() {
return format!("{}", pid);
return pid.to_string(); // Bolt: Use to_string() instead of format! for single integer conversion

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This inline comment is redundant and adds unnecessary noise to the codebase. The use of to_string() is idiomatic and self-explanatory, so the comment can be safely removed.

Suggested change
return pid.to_string(); // Bolt: Use to_string() instead of format! for single integer conversion
return pid.to_string();

}
}
"1".to_owned()
Expand All @@ -715,7 +715,7 @@ fn render_proc_file(fs: &ProcFilesystem, kind: ProcLiveFileKind) -> String {
if let Some(provider) = PROCESS_PROVIDER.get() {
let pids = provider.process_pids();
if let Some(&min_pid) = pids.iter().min() {
return format!("{}", min_pid);
return min_pid.to_string(); // Bolt: Use to_string() instead of format! for single integer conversion

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This inline comment is redundant and adds unnecessary noise to the codebase. The use of to_string() is idiomatic and self-explanatory, so the comment can be safely removed.

Suggested change
return min_pid.to_string(); // Bolt: Use to_string() instead of format! for single integer conversion
return min_pid.to_string();

}
}
"1".to_owned()
Expand Down Expand Up @@ -1016,7 +1016,7 @@ impl DirNodeOps for ProcNode {

if let Some(fds) = provider.process_fds(pid) {
for fd in fds {
let name = format!("{}", fd);
let name = fd.to_string(); // Bolt: Use to_string() instead of format! for single integer conversion to avoid allocation overhead

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This inline comment is redundant and adds unnecessary noise to the codebase. The use of to_string() is idiomatic and self-explanatory, so the comment can be safely removed.

Suggested change
let name = fd.to_string(); // Bolt: Use to_string() instead of format! for single integer conversion to avoid allocation overhead
let name = fd.to_string();

let child_ino = PID_INODE_START + (pid << PID_INODE_SHIFT) + SUB_INO_FD_BASE + fd as u64;
all_entries.push((name, child_ino));
}
Expand All @@ -1032,7 +1032,7 @@ impl DirNodeOps for ProcNode {
if self.ino == ROOT_INO {
if let Some(provider) = PROCESS_PROVIDER.get() {
for pid in provider.process_pids() {
let name = format!("{}", pid);
let name = pid.to_string(); // Bolt: Use to_string() instead of format! for single integer conversion to avoid allocation overhead

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This inline comment is redundant and adds unnecessary noise to the codebase. The use of to_string() is idiomatic and self-explanatory, so the comment can be safely removed.

Suggested change
let name = pid.to_string(); // Bolt: Use to_string() instead of format! for single integer conversion to avoid allocation overhead
let name = pid.to_string();

let child_ino = PID_INODE_START + (pid << PID_INODE_SHIFT) + SUB_INO_DIR;
all_entries.push((name, child_ino));
}
Expand Down